Tap here to switch tabs
Problem
Submissions

Problem: Next Greater Element III

med
30 min
Explore how to use the two-pointer technique to find the smallest integer greater than a given number with the exact same digits. Understand constraints such as 32-bit integer limits and improve your problem-solving skills with this pattern. Practice implementation in Python to prepare for technical interviews.

Statement

Given a positive integer n, find the smallest integer that uses exactly the same digits as n and has a strictly greater value than n. If no such positive integer exists, return −1-1.

Note: If a valid answer exists but does not fit within a 3232-bit signed integer, return −1-1.

Constraints:

  • 1≤1 \leq n ≤231−1\leq 2^{31} - 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Next Greater Element III

med
30 min
Explore how to use the two-pointer technique to find the smallest integer greater than a given number with the exact same digits. Understand constraints such as 32-bit integer limits and improve your problem-solving skills with this pattern. Practice implementation in Python to prepare for technical interviews.

Statement

Given a positive integer n, find the smallest integer that uses exactly the same digits as n and has a strictly greater value than n. If no such positive integer exists, return −1-1.

Note: If a valid answer exists but does not fit within a 3232-bit signed integer, return −1-1.

Constraints:

  • 1≤1 \leq n ≤231−1\leq 2^{31} - 1