I have the following code that counts the number of pairs in an array that have a sum below the maximum,
def findPairs(arr, x):
l = 0; r = len(arr)-1
result = 0
while (l < r):
if (arr[l] + arr[r] < x):
result += (r - l)
l += 1
else:
r -= 1
return result
arr = [1, 2, 3, 4, 5, 6, 7, 8]
n = len(arr)
x = 7
print(findPairs(arr, x))
I need to edit it in order to return a list of the pair with the maximum sum not exceeding the maximum parameter (x). If there are multiple pairs with the maximum sum then one pair is chosen at random