06 / 19

What is the Sliding Window technique? Give a use case.

Sliding Window

javascript
  1. 1

    Useful for contiguous subarray or substring problems.

  2. 2

    A common use case is finding the longest substring without repeating characters.

  3. 3

    Another use case is finding the minimum-length subarray satisfying a condition.

  4. 4

    Many sliding-window solutions reduce a brute-force O(n²) approach to O(n).

  5. 5

    The exact validity condition depends on the problem and data properties.

Difficulty: 3/10

Follow-up Questions

  • Solve longest substring without repeating characters.
  • When does sliding window fail for negative numbers?