> For the complete documentation index, see [llms.txt](https://interviews.woojiahao.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://interviews.woojiahao.com/data-structures/queues.md).

# Queues

## Runtime analysis

1. Enqueue/offer: $$O(1)$$
2. Dequeue/poll: $$O(1)$$
3. Front: $$O(1)$$
4. Back: $$O(1)$$
5. isEmpty: $$O(1)$$

## Take note…

1. Built in data structure like `[]` in Python use $$O(n)$$, not $$O(1)$$
   * Check if can assume data structure is optimal
   * To optimize for Python, use `from collections import deque` instead to `popleft()`

## Corner cases

1. Empty queues
2. Queue with one item
3. Queue with two items

## Techniques

### Rotating the queue on itself

Pop the queue and push back onto itself to bring the last element to the front
