17. Next Greater on the Board
Easy
The array consulta contains distinct values that also appear in painel, where all values are distinct. For each queried value, return the first greater value to its right in painel. Use -1 when none exists.
Example 1
Input: consulta = [3, 1], painel = [1, 3, 4, 2]
Output: [4, 3]
Explanation: To the right of 3 comes 4; to the right of 1 comes 3.
Example 2
Input: consulta = [5, 2], painel = [2, 5, 1]
Output: [-1, 5]
Constraints
- 0 <= consulta.length <= painel.length <= 10^4
- The values in `painel` are distinct.
- Each value in `consulta` appears in `painel`.
ArraysStackHash map
Saved in this browser
Caso 1
consulta =
[3,1]
painel =
[1,3,4,2]
Expected =
[4,3]
Caso 2
consulta =
[5,2]
painel =
[2,5,1]
Expected =
[-1,5]
Run checks these 2 cases. Submit runs all 6, including hidden ones.