Skip to main content

Essential Two Pointers & Sliding Window Problems for SDE Interviews

· 7 min read

If you're heading into placement season or want to master one of the most versatile problem-solving techniques in DSA, this list is for you. Two Pointers and Sliding Window are patterns you'll encounter in almost every interview, whether it's a FAANG-style round or a product startup's online assessment.

These aren't random problems. They're hand-picked to cover every sub-pattern, from simple opposite-end pointers to complex variable-length window problems with character frequency maps.

I've organized them by pattern type because that's how your brain should work during interviews. Once you recognize "this needs a shrinking window" or "this is a classic two-sum variant," the rest follows naturally.

Connect with me on LinkedIn to stay updated with more coding resources, interview tips, and problem-solving strategies!


Problem List by Pattern

1. Two Pointers on Sorted Arrays

  1. Two Sum II - Input Array Is Sorted
  2. 3Sum
  3. 3Sum Closest
  4. 4Sum
  5. Container With Most Water
  6. Trapping Rain Water
  7. Remove Duplicates from Sorted Array
  8. Remove Duplicates from Sorted Array II
  9. Squares of a Sorted Array

2. Two Pointers on Strings & Palindromes

  1. Valid Palindrome
  2. Valid Palindrome II
  3. Reverse Vowels of a String
  4. Reverse Words in a String III
  5. Palindromic Substrings
  6. Longest Palindromic Substring

3. Fast & Slow Pointers (Cycle Detection)

  1. Linked List Cycle
  2. Linked List Cycle II
  3. Find the Duplicate Number
  4. Middle of the Linked List
  5. Happy Number
  6. Remove Nth Node From End of List

4. Fixed-Size Sliding Window

  1. Maximum Average Subarray I
  2. Maximum Sum of Almost Unique Subarray
  3. Find All Anagrams in a String
  4. Permutation in String
  5. Number of Equal Count Substrings
  6. Maximum Points You Can Obtain from Cards
  7. Substrings of Size Three with Distinct Characters

5. Variable-Size Sliding Window (Longest/Smallest)

  1. Longest Substring Without Repeating Characters
  2. Longest Repeating Character Replacement
  3. Minimum Window Substring
  4. Minimum Size Subarray Sum
  5. Longest Substring with At Most Two Distinct Characters
  6. Longest Substring with At Most K Distinct Characters
  7. Fruits Into Baskets
  8. Max Consecutive Ones III
  9. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit

6. Sliding Window with Counts & Conditions

  1. Count Number of Nice Subarrays
  2. Binary Subarrays With Sum
  3. Subarrays with K Different Integers
  4. Number of Substrings Containing All Three Characters
  5. Frequency of the Most Frequent Element
  6. Replace the Substring for Balanced String
  7. Count Subarrays With Score Less Than K

7. Two Pointers for Merging & Partitioning

  1. Merge Sorted Array
  2. Sort Colors
  3. Move Zeroes
  4. Partition Array According to Given Pivot
  5. Partition Labels
  6. Interval List Intersections
  7. Shortest Word Distance

8. Advanced Sliding Window & Two Pointers

  1. Minimum Window Subsequence
  2. Count Subarrays Where Max Element Appears at Least K Times
  3. Maximum Number of Vowels in a Substring of Given Length
  4. Maximize the Confusion of an Exam
  5. Get Equal Substrings Within Budget
  6. K Radius Subarray Averages
  7. Minimum Operations to Reduce X to Zero

9. Competitive Programming Classics

  1. Maximum Subarray Sum
  2. Collecting Numbers
  3. Array Division
  4. ABC 130 D - Enough Array
  5. ABC 155 D - Pairs
  6. ABC 188 D - Snuke Prime
  7. CF - The Two Routes
  8. CF - Vasya and String
  9. CF - String Transformation

Why This List Works

Pattern-Based Organization: Two Pointers and Sliding Window are deceptively similar — this list separates them clearly so you build the right mental model for each.

Progressive Difficulty: Starts from foundational problems (valid palindrome, two sum II) and builds to complex window counting problems and competitive programming challenges.

Covers Both Strings and Arrays: Most guides focus only on array problems. This list covers string sliding window extensively, which is crucial since many interview problems involve character frequency maps.


Final Thoughts

Two Pointers and Sliding Window problems are among the most rewarding to master. Once you internalize the shrink-expand window technique and the opposite-ends pointer approach, you'll solve problems that look intimidating in under 10 minutes.

Focus on understanding when to shrink the window and which condition you're maintaining — that's the core insight for 90% of these problems.

Let's connect on LinkedIn - I regularly share interview tips, problem-solving strategies, and coding resources that can help accelerate your preparation!

You've got this!