I'm getting TLE in DIGJUMP. Please help me, I have checked my code and I'm unable to find the reason for TLE

I’m trying to solve this question (link DIGJUMP - Editorial ).
I have used modified bfs and I have already gone through all the test cases provided in the comment section of the editorial by other users and I’m getting correct and for all the testcases.

Consider the test case where S is 100000 0s.

1 Like

My code’s output: 2 (1 -> 0 (first occurrence) -> 0 (last occurrence ) )
Am I correct or is something missing in my logic?

On my machine, your code gives the output:

1

but it takes 18 seconds to do it.

1 Like