Skip to main content

DSA pattern

Two Pointers

The two pointers technique uses two indices to iterate through a data structure, often from opposite ends or at different speeds. This pattern is essential for sorted array problems, palindrome checking, and finding pairs that meet certain criteria.

When to use

5 signals
  1. 01Working with sorted arrays or strings
  2. 02Finding pairs or triplets with a target sum
  3. 03Checking for palindromes
  4. 04Removing duplicates in-place
  5. 05Container with most water problems

In interviews, call out the pattern early. It helps interviewers follow your reasoning and keeps your implementation focused. After solving, explain tradeoffs in plain language: why this approach is efficient, where it can break, and what edge cases you would test first.

Practice problems

5 listed
  1. 01Two Sum IIPractice →
  2. 02Valid PalindromePractice →
  3. 03Container With Most WaterPractice →
  4. 043SumPractice →
  5. 05Trapping Rain WaterPractice →

Build a review loop

Treat each pattern as a repeating cycle, not a one-time read. Solve a fresh problem today, revisit the same pattern in 2-3 days, and run one timed attempt at the end of the week. This turns short-term familiarity into reliable recall for live interviews.

When reviewing, re-derive the core steps from scratch before checking a reference solution. If you can explain the state transitions and edge cases clearly, you are much more likely to execute well under interview pressure.