INCORRECT ANSWER

although i am getting the output, its not sorted in the correct way. can you tell me how is that supposed to be done. do i need to store the outputs and then sort them ?

you can sort the output by making custom comparator, your logic is correct but you are starting from back of the n so you just need to start recurring from the front , since you have taken n as int so computing front digit is little complex which we can ease by taking n as a string

refer code for more clearity

In case of any doubt feel free to ask :slight_smile:
mark your doubt as resolved if you got the answer