There is an array with distinct elements given. Determine the next greater element for each element of the array in order of their appearance in the array. The next greater element for an element in the array is the greater element on the right side. Consider the next greater element as -1 for elements for which no greater element exists.
Write a function
solve that have the following parameter(s):
1.) arr = array of integer
There is an array of integers:
arr = [2, 3, 1, 4]
The function will return,
[3, 4, -1]
In the array, the next larger element to 2 is 3, 3 is 4 and for 4 it doesn't exist, it is -1.