data structure that allows constant-time insertion (O(1)) and removal form both ends

implementing it in TS to understand better:

internally use an array to keep track of elements use pointer to head and tail to keep track of where to add new elements from either side