Chewbacca and numbers


only 3 test case running

Hey @bhattanurag426 see for this test case: 332711047202
Your output is: 2142413342
But Expected output is: 332211042202
I can see the implementation you have followed is not ideal. If you want any idea for the implementation, then do let me know

yes sir i want the idea for implementation

What the questtion is asking is basically that what is the possible smallest number we can get by interchanging digits (changing t to 9-t) .
Now if we already have the smallest number that can be : we will change 0 digits
Otherwise we will change some digits to make it the smallest number

For ex : 4545 has two digits which when interchanged will give a smaller number ( 5 when interchanged will give 4 ) so all the 5 in the number arre changed and the output becomes 4444.

Hint : Change all the numbers with value >4 . But keep in mind that you cannot make the first number 0.

I am attaching my code here so that you can refer that also

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.