I wrote a code but test cases 2 and 4 are wrong


what needs to be improved in this code

@HemantNasa,
Input:
99
correct output 90
your code gives 0

Areee… I somehow managed to solve case 4 but still test case 2 is wrong… : ) https://ide.codingblocks.com/s/265799

@HemantNasa,
Input:
92
Correct output: 92
Your output: 2

can you please provide the logic… I think i misunderstood it… Where to invert where to not… I’m inverting all digit which are min… that’s why my answer is 2 but 92 is exactly the same in answer… Means I misunderstood the concept

@HemantNasa,

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

areee Thank you bro… ab Jakr hua complete… Saviour for me… Like a gaurdian for me… Done… Thanks again