Approach hintTry it first, then revealHide
Scan from the right while tracking the smallest digit seen so far. A digit with a smaller digit somewhere after it has to be moved, so it becomes min(d + 1, 9); finally output all digits in sorted order.
Scan from the right while tracking the smallest digit seen so far. A digit with a smaller digit somewhere after it has to be moved, so it becomes min(d + 1, 9); finally output all digits in sorted order.