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.