7.Next Greater Element II
Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the first greater number to its traversing-order next in the array, which means you could search circularly to find its next greater number. If it doesn't exist, output -1 for this number.
Solution I: (Brute Force)
Creating an array of size 2 * n and searching
Time Complexity: O(N^2)
Solution II: (Using stack)
To get in a circular array we iterate through the array twice
Time Complexity: O(N)
Last updated