Ad
  • Custom User Avatar

    The problem is with your current algorithm. Consider what would happen if you got the input: 90000000000000001? It should be pretty clear that the next smaller with the same digits is 19000000000000000, yet if your algorithm starts by counting backward from 90000000000000001 all the way down, it will timeout long before reaching the correct answer.

    Think about writing an algorithm that transforms the input rather than one that brute-forces a counter and checks if the result has the same-digits.

    Good luck!