Chewbacca And Number

Can you explain why is it failing test case 2 and 4 ?

@Karanveer, In the question you can replace a number with 9-t but you can’t remove it
i.e the number of digits in the input number should be same as in the output number, which is apparently not the case in the solution you have provided
Your code majorly fails for the cases when the input number starts with 9
for eg :-
999 (no’ of digits is 3)
your code output :- 0
correct ans:- 900 (no’ of digits is 3, and since the number can’t have leading 0, thus we can’t replace the starting 9, but can replace other digits with 0)

eg:-
95875
your output :- 4124
correct output :- 94124
I hope you got the cue of what i am trying to say

In case of any doubt feel free to ask :slight_smile:
If you got the answer then mark your doubt as resolved

https://ide.codingblocks.com/s/256180 , still 2 test cases are failing…

@Karanveer, at line 29,
change it to :-
cout << min((9-x),x) *cnt + sum;

because you are not checking minimum for most significant digit

1 Like

Alright, got that… thanks for help…