1. Understand the problem

1.1. Explain the main idea of the problem

We are given a positive integer n.

Our task is to find the smallest integer strictly greater than n that uses exactly the same digits as n.

In other words:

Example:

n = 4365

We can rearrange its digits to form:

436543564536456346354653...

We only consider numbers greater than 4365.

The smallest valid number is:

4536

Therefore: