Logic is not clear to me

I’m not able to understand the question can you plzz help me with it and i code in java lang soo try to explain in java only

@Sadaf_khan0107,

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

Also input can be quite big so use long.

thnks @sanchit.bansal06

@Sadaf_khan0107,

Please mark the doubt as resolved if your query has been answered.

And you can further rate your experience with me as well. Thanks. :smile:


this is my code but only 2 test cases are passed by this code can u plz tell me the errors
@sanchit.bansal06

@Sadaf_khan0107,
While sharing your code through CB ide follow these steps:
select the correct language, copy your code, click on save, share the link

Test case:
99999
Correct output:
90000
your output:
99999

@Sadaf_khan0107,
You still haven’t corrected your code for the input I gave you.

https://ide.codingblocks.com/s/235935 corrected code.