human
Find the maximum possible value of a [ i ] % a [ j ] over all pairs of i and j | Function that returns the second largest element in the array if exists , else 0.
There must be at least two elements.
To store the maximum and the second maximum element from the array.
If current element is greater than first then update both first and second.
If arr [ i ] is in between first and second then update second.
No second maximum found.
Driver code"
How can the above be solved in Python?

Write me a code to find the maximum possible value of a [ i ] % a [ j ] over all pairs of i and j and the other steps required?
assistant
#Here is code to find the maximum possible value of a [ i ] % a [ j ] over all pairs of i and j and the other steps required.
 def getMaxValue ( arr , arr_size ) :
	if ( arr_size < 2 ) :
		return 0
	first = - sys . maxsize - 1
	second = - sys . maxsize - 1
	for i in range ( arr_size ) :
		if ( arr [ i ] > first ) :
			second = first
			first = arr [ i ]
		elif ( arr [ i ] > second and arr [ i ] != first ) :
			second = arr [ i ]
	if ( second == - sys . maxsize - 1 ) :
		return 0
	else :
		return second
if __name__ == ' _ _ main _ _ ' :
	arr = [ 4 , 5 , 1 , 8 ]
	n = len ( arr )
	print ( getMaxValue ( arr , n ) )