Practice Next Greater Element III
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
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.
Source: Next Greater Element III on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
n = 12
21
# Example 2
n = 21
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Next Greater Element III.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.