55. Next Greater Element
MediumStacks
For each element of nums, return the first larger element to its right, or -1 if none exists.
Example 1
Input: nums = [4, 5, 2, 25] Output: [5, 25, 25, -1]
Constraints
1 ≤ nums.length ≤ 10⁵
MediumStacks
For each element of nums, return the first larger element to its right, or -1 if none exists.
Input: nums = [4, 5, 2, 25] Output: [5, 25, 25, -1]
1 ≤ nums.length ≤ 10⁵Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor
Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.
Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.