instagram

Next greater element in an array

Algorithm to find next greater element in array for current element.

If we do linear search then it would take O(n^2) but here we are going to use stack to implement this algorithm. It will going to take O(n) time.

Output
-1
54
-1
20
27
27
-1

Share