Two Pointers Cheat Sheet

You usually start one pointer at each end of the list and move them toward each other. That way you need one pass instead of a nested loop.

When to use it

  • You need a pair or a small group of numbers that adds up to a target.
  • You're checking whether a list or string reads the same from both ends, like a palindrome.
  • The list is sorted or the order doesn't matter. You'd need two nested loops without this pattern.
  • You want to use O(1) extra space. That rules out a hash map or a second list.

What's on the sheet

The sheet has a code template you can reuse for every Two Pointers problem. It's split into four steps so you can see which part changes from problem to problem. It also shows how to spot the pattern, how fast it runs, the mistakes people often make and the variations you'll see in interviews.

How to get it

This one is free for everyone. You can open it any time.