Time Complexity

  • O(1) to offer() - push in an element
  • O(1) to poll() - pop out an element
  • O(1) to peek() - read the element that is the first to be pop out


Implementation with Circular Array

Implementation with Single Linked List

  • Visual
  • push() from tail node
  • pop() & peek() from the head node

Monotonic Queue

  • Finding the biggest element in a sliding window