Next Greater Element in an array

Problem Given an array, print the next greater element for every element. Elements for which no greater element exist, print next greater element as -1. Example For the elements of the array [4, 5, 2, 25, 20, 11, 13, 21, 3] greater elements are as follows. 4 –> 5 5 –> 25 2 –> 25 25 –> -1 20 –> 21 11 –> 13 13 –> 21 21 –> -1 [Read More]