Skip to main content

Sliding Window: Fixed

A subset of the Two Pointer Method, but uses left and right pointers to define the bounds of a "window" in iterable data structures like arrays. The window defines the subcomponent, like subarray or substring, and it slides across the data structure in one direction, searching for a subcomponent that meets a certain requirement. 

When to use:

  • Data Structure: Linear such as Array, Linked List
  • Find a Subcomponent of a length

Brute Force:

  • Finding all possible subcomponents for an answer using a Nested Loop
    • Outer Loop traverses the array for the first element of the pair
    • Inner Loop traverses the rest of the array to find second element 
  • Time Complexity is O(n^2) where n is length of the loop ( Two Loops )

Real-World Example:

Buffering in Video Streaming