[Stack] JS Solution
\n/*\nWe are looking for the first number greater than current number. It doesn\'t matter if the\nposition of Next Greater Number (NGN) is before or after posit
```\n/*\nWe are looking for the first number greater than current number. It doesn\'t matter if the\nposition of Next Greater Number (NGN) is before or after position of current number because\nthe array is circular.\n\nWe will use a Stack. We start iterating given array from the start.\nAt each number, we check if stack has a number smaller than current number. If so,\ncurrent number is the Next Greater Number for that element in the stack. Hence,\nwe keep popping smaller elements from stack and be their NGN. \n\nThen, we push current number into stack so that we can find our NGN (or not if there isn\'t one).\n\nWe will push index instead of number into stack so that we can fill our result array.\n\nAlso, we will iterate through the array twice so that for every number we can scan elements on both the left side and the right side.\n*/\n\nvar nextGreaterElements = function(nums) {\n    let res = new Array(nums.length).fill(-1);\n    let stack = [];\n    for (let i = 0; i < nums.length * 2; i++) {\n        let j = i % nums.length;\n        while (stack.length > 0 && nums[stack[stack.length-1]] < nums[j]) {\n            // current element is NGN for popped element\n            res[stack.pop()] = nums[j];\n        }\n        stack.push(j);\n    }\n    return res;\n    // T.C: O(N)\n    // S.C: O(N)\n};\n```
['JavaScript']