How to reduce runtime

, ,

You are getting TLE because of the wrong implementation of this loop.

while (fon >= 0) {
        if (fon%10 == 0) {
        fon = fon/10;

The smallest value of fon in the loop will be zero, now a/c to the condition the loop should run for zero too, and this time fon=fon/10 will have no effect on it thus the value of fon remains 0 for next loop and so on, making it run infinitely.

1 Like
  1. Your loop condition is wrong because β€˜fon is greater and equal to 0’. here you have to remove the equal condition and code be like this, while (fon > 0) {} .