Most languages have built-in deques:
- C++:
deque<T>withpush_front,push_back,pop_front,pop_back - Python:
collections.dequewithappendleft,append,popleft,pop - Java:
ArrayDequeorLinkedListimplementingDequeinterface
Never implement a deque from scratch in contests.
Use the standard library. Focus on the algorithm. Time: . Space: .