[JAVA] self explanatory O(n)
```\nclass Solution {\n    public int[] nextGreaterElements(int[] nums) {\n      Stack st = new Stack<>();\n      for(int i = nums.length - 1; i >= 0; i --) {\n
```\nclass Solution {\n    public int[] nextGreaterElements(int[] nums) {\n      Stack<Integer> st = new Stack<>();\n      for(int i = nums.length - 1; i >= 0; i --) {\n       st.push(nums[i]); \n      }\n      \n      int ans[] = new int[nums.length];\n      for(int i = nums.length - 1; i >= 0; i --) {\n        while(!st.isEmpty() && st.peek() <= nums[i]) {\n          st.pop();\n        }\n        ans[i] = st.empty() ? -1 : st.peek();\n        st.push(nums[i]);\n      }\n      return ans;\n    }\n}
['Stack', 'Monotonic Stack', 'Java']