How about this:

The only reversals that increase the price are 2 --> 5 and 6 --> 9.

We traverse from right-most digit to left-most digit and see if it's a
2 or a 5, if it is, then we reverse and thus we get the probable next
max value.

Next we sort the digits present in the number and for each digit in the
number starting from right to left, we swap that digit with the next
higher digit, if present to get a probable next max value.

Thus we obtain a set of "probable next max values", the least of all
this that is greater than the given number is the answer.

So if we take the example of 62.5, then the first pass will give us
65.5
Sorting the digits we get 2,5,6. So second pass will give us, 52.6,
65.2
Hence the answer is 65.2.

Reply via email to