Given a number N find the biggest possible number X that can be created from the given number digits.
Example: N=231 then X will be 321.
The restrictions are time complexity O(1) and space complexity O(1).
I think this has to be done with counting sort.
Best I can do is O(1) space and O(log(N)) time. Pretty sure it's impossible to do any better because at the bare minimum you have to analyze each digit in the input, which is log(N) right there.
The short answer is, sort the digits of N in descending order.
Pseudocode:
Sample Python implementation:
Result:
321