HELP WANTED, Getting TLE in O(n)!

I am posting first time on codechef, so i am trying this question Mayhem Again | CodeChef from 3-4 days, its a basic bfs question and i am clearly using O(n) time complexity here is the submission link : Solution: 42882398 | CodeChef but i am still getting TLE i don’t know why , i have even tried the same question using DFS (recursive) but that also gave me TLE.
I seriously need help i really want to know what’s wrong in here.
Please Help, Thankyou.

1 Like

I just checked your code and even I was not able to find anywhere you wasted any time! The worst case scenario i can think would be still O(n) according to me! Codechef really need to look into this

1 Like

Everybody knows Python takes long time to execute… Why don’t you try C++…

bro, there are many solutions on python too which executed within time limits for example take this Solution: 42866567 | CodeChef.