Search⌘ K
AI Features

Solution: Next Greater Element III

Explore how to apply the two pointers technique to solve the Next Greater Element III problem by finding the smallest integer greater than a given number using the same digits. This lesson teaches you to identify the pivot, swap digits, and reverse suffixes while ensuring solutions fit 32-bit integer limits.

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 ...