Queue problems are less common but it is still a data structure that is worth understanding well
Enqueue/offer: O(1)O(1)O(1)
Dequeue/poll: O(1)O(1)O(1)
Front: O(1)O(1)O(1)
Back: O(1)O(1)O(1)
isEmpty: O(1)O(1)O(1)
Built in data structure like [] in Python use O(n)O(n)O(n), not O(1)O(1)O(1)
[]
Check if can assume data structure is optimal
To optimize for Python, use from collections import deque instead to popleft()
from collections import deque
popleft()
Empty queues
Queue with one item
Queue with two items
Pop the queue and push back onto itself to bring the last element to the front
Last updated 2 years ago