Chewbacca and Numbers

I am not able to solve can you please give a hint?

Start from the leftmost digit and check if its better than replacing it with 9 - t, if its is, do so and move on to the next digit.

But why start from the left end and how to access the left most digit of a number?

you can start from either end and for accessing each digit, just mod number each time by 10 and then diviide the number by 10

Pls look at the code https://ide.codingblocks.com/s/226984.
I am getting one wrong answer and 2 run error.

Take everything in long. and check the corner cases for the number produced with leading zeros. These are the cases where your code is wrong

are these the corner cases : 00987, 0999 ?

No, the cases where your code can go wrong is where the number begins with a 9 and your code will check and see that since 9 - 9 i.e. 0 is less than 9, it will replace it with 0, but that would produce a result with leading zeros. This is what I mean, and please provide the new link to your code with all the things changed to long data type so I can have a look.


Pls have a look.

No, the logic still isn’t correct. You should avoid changing only those 9’s that occur in the starting of the number, elsewhere you are good to go.

Can you pls give some example numbers, I am still not able to understand. And When I submit the code I am getting run error, why?

Thanks for the help!!
There was a problem while taking input, I had used s.nextInt(); instead of s.nextLong(); that’s why I was getting rum time error.