2018-10-19 12:48:28 +00:00
|
|
|
def printNGE(arr):
|
2019-10-18 19:14:01 +00:00
|
|
|
"""
|
|
|
|
Function to print element and Next Greatest Element (NGE) pair for all elements of list
|
|
|
|
NGE - Maximum element present afterwards the current one which is also greater than current one
|
|
|
|
>>> printNGE([11,13,21,3])
|
|
|
|
11 -- 13
|
|
|
|
13 -- 21
|
|
|
|
21 -- -1
|
|
|
|
3 -- -1
|
|
|
|
"""
|
2018-10-19 12:48:28 +00:00
|
|
|
for i in range(0, len(arr), 1):
|
2019-08-19 13:37:49 +00:00
|
|
|
|
2018-10-19 12:48:28 +00:00
|
|
|
next = -1
|
2019-10-05 05:14:13 +00:00
|
|
|
for j in range(i + 1, len(arr), 1):
|
2018-10-19 12:48:28 +00:00
|
|
|
if arr[i] < arr[j]:
|
|
|
|
next = arr[j]
|
|
|
|
break
|
2019-08-19 13:37:49 +00:00
|
|
|
|
2018-10-19 12:48:28 +00:00
|
|
|
print(str(arr[i]) + " -- " + str(next))
|
2019-08-19 13:37:49 +00:00
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
|
2018-10-19 12:48:28 +00:00
|
|
|
# Driver program to test above function
|
2019-10-05 05:14:13 +00:00
|
|
|
arr = [11, 13, 21, 3]
|
2018-10-19 12:48:28 +00:00
|
|
|
printNGE(arr)
|