I considered begining with zero till end , but still two testcases are failing
I considered begining with zero till end
Input:
93
Your Output:
3
Correct Output:
93
Suggested 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
Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn’t start with a zero.
input 93
my output 3
correct output 93
why 93?
@sushant4573,
Yeah you cannot start a number with 0. If the input is 62, the output will be 32. If the input is 92, the output will be 92.
The question description says that:
Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn’t start with a zero.