Search
⌘K

Leetcode 2454. Next Greater Element IV

For each element in nums, find the first element to its right that is strictly greater and then the next strictly greater element after that (i.e., the "second greater" to the right), or return -1 if none exists. The challenge is to compute all answers efficiently for n up to 1e5, typically using monotonic-stack techniques to track candidate indices.

Asked at:

DoorDash


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Late June, 2025

DoorDash

Staff

Given a positive integer n, find the smallest integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive integer exists, return -1. Note that the returned integer should fit in 32-bit integer, if there is a valid answer but it does not fit in 32-bit integer, return -1.

Comments

Your account is free and you can post anonymously if you choose.