Abstract


Complexity


Space

Time

  • 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


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

Variant


Monotonic Queue

  • Finding the biggest element in a sliding window

Questions