30:00
You are given an integer num. You may swap two of its digits at most once. Return the largest number you can get.
0≤num≤1080 \leq \text{num} \leq 10^80≤num≤108
Run code to see results.
We may swap two digits of 2736 once. A bigger digit moved to the front adds the most value.
2
0
.
7
1
3
6
last[d]: rightmost position of digit d (probed from 9 down)
9
-
8
5
4
original
2736
best so far
You get a non-negative integer and may swap two of its digits once. Return the largest number you can make.