<aside>

This section is part of the 5-hour LeetCode DSA Patterns course by Mukul Raina

SLIDE 25: Section Intro, Two Pointers and Sliding Window

Section 3: Two Pointers and Sliding Window

In Section 2, we eliminated redundant lookups with hash maps and redundant range calculations with prefix sums. This section tackles a different bottleneck: problems where the answer depends on a contiguous range or two positions in an array, and the brute force tries every possible pair or every possible subarray.

Two pointers and sliding window are techniques that move through the array in a structured way, skipping work that cannot lead to a better answer. Instead of checking all O(n²) pairs or subarrays, you maintain one or two pointers that only move forward, giving you O(n) solutions.

What We’ll Cover:

  1. Opposite-direction two pointers
  2. Same-direction two pointers
  3. Fixed-size sliding window
  4. Variable-size sliding window
  5. Character frequency windows
  6. Decision framework: two pointers vs sliding window

Where This Appears in Interviews:

Company Type How This Section Appears
FAANG / Big Tech 3Sum, Container With Most Water, and Minimum Window Substring are top-20 most-asked problems
Mid-size companies Palindrome checks, duplicate removal, and substring problems appear frequently in phone screens
Startups String processing and data stream problems that reduce to sliding windows
Online assessments Variable-size window problems are common timed questions where O(n) vs O(n²) determines pass/fail

Core Idea for This Section: When the answer depends on a contiguous range or two positions moving through sorted/sequential data, pointer movement replaces nested loops. The skill is knowing which pointer to move and when.

<aside>

Mukul Raina | youtube.com/@mukulraina | slides.mukulraina.com | LinkedIn

</aside>


SLIDE 26: Opposite-Direction Two Pointers

Recognition Signal: The input is a sorted array, string, or sequence, and the problem asks about pairs, symmetry, or convergence from both ends. You notice that checking all pairs would be O(n²), but if the data is sorted, you can eliminate many pairs at once by reasoning about the values at each end.