human
Give me a code to largest number having both positive and negative values present in the array and the other steps required given the following:
Largest number having both positive and negative values present in the array | Function to find the largest number k such that both k and - k are present in the array.
Stores the array elements.
Initialize a variable res as 0 to store maximum element while traversing the array.
Iterate through array arr.
Add the current element into the st.
Check if the negative of this element is also present in the st or not.
Return the resultant element.
Drive Code"
Solution in Python:
assistant
#Here is code to largest number having both positive and negative values present in the array and the other steps required.
 def largestNum ( arr , n ) :
	st = set ( [ ] )
	res = 0
	for i in range ( n ) :
		st . add ( arr [ i ] )
		if ( - 1 * arr [ i ] ) in st :
			res = max ( res , abs ( arr [ i ] ) )
	return res
arr = [ 3 , 2 , - 2 , 5 , - 3 ]
n = len ( arr )
print ( largestNum ( arr , n ) )