No solution in python (only partially correct)


even the editorial solution in python is only giving partial correct answer. it is giving time limit error for the rest.


If you are using list as a queue and using insert for inserting at start, it will give TLE.
However if you use deque and use popleft and append and appendleft, it gets accepted.

Looks like internally deque is faster.


thanks @sprokr, my logic got accepted when using deque instead of pop(0)


Faced the same issue. Thanks @sprokr.