Given an array, find the nearest smaller element G[i] for every element A[i] in the array such that the element has an index smaller than i.
G[i] for an element A[i] = an element A[j] such that j is maximum possible AND j < i AND A[j] < A[i]
Elements for which no smaller element exist, consider next smaller element as -1.
A : [4, 5, 2, 10, 8]
[-1, 4, -1, 2, 2]
A : [3, 2, 1]
[-1, -1, -1]
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.