Not passing all test cases
Hey @kartiksaxena2000 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
Okoy got it the isuue was cuz of Very long numbers so had to use long long int, now it has passes all test cases. But ya i would like to know a more efficient approach
The logic behind this Problem was pretty simple as we can invert any digit ( 9 - digit) but we need to invert only such digits that will eventually end up giving the smallest number possible.
So, we should invert only digits greater then or equal to 5 as after inverting them, the result gives us smallest number.
For e.g.,
9 - 5 = 4 viz, smaller than the original number that was 5.
9 - 8 = 1 viz, smaller than the original number that was 8.
but 9 - 1 = 8 viz, greater than the original number that was 1.
Important point to consider is, After inverting any digits their should not be trailing zeros that means, if their is 9 at the starting of the number then it must remain the same
I am guessing u will take input as a string and then will traverse it and invert the required digits???
Yes this is the intuition behind this
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.