Problem 60206. Find Next Strictly Greater Element
Given an array of numbers, create a new array where each element represents the next strictly greater element to the right of the corresponding element in the input array x. If there is no next greater element, put -1.
For example, given x = [1 3 2 4], the output should be [3 4 4 -1] because:
- The next greater element to 1 is 3.
- The next greater element to 3 is 4.
- The next greater element to 2 is 4.
- There is no next greater element to 4, so it is -1.
Solution Stats
Problem Comments
-
1 Comment
Dyuman Joshi
on 12 Jun 2024
Just like #60186, this is a misleading problem as well.
Will be interesting to find an efficient method for it - both speed and memory wise.
Solution Comments
Show commentsProblem Recent Solvers8
Suggested Problems
-
Return a list sorted by number of occurrences
2819 Solvers
-
Check to see if a Sudoku Puzzle is Solved
325 Solvers
-
middleAsColumn: Return all but first and last element as a column vector
613 Solvers
-
Calculate the Hamming distance between two strings
324 Solvers
-
Path calculation with polynomials
44 Solvers
More from this Author53
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!