Talentd
FleetCode
Make and follow sheets.Sign in

Two Pointers Problems (252)

Problems tagged with Two Pointers. Start with the easy ones, then move to medium and hard.

70 Easy150 Medium32 Hard

Learn these first

1
Array

Most Two Pointers problems operate on arrays. Understanding indexing, iteration, and in-place modification is essential before applying pointer movement strategies.

2
String

Many interview questions apply the technique to strings for palindrome checks, substring comparisons, and character-based scanning problems.

3
Sorting

Several Two Pointers solutions rely on sorted input. Knowing sorting algorithms helps you prepare data so opposite-direction pointers can efficiently find pairs or ranges.

4
Hash Table

Some problems combine pointers with hash tables to track frequencies or previously seen values while scanning the array.

5
Sliding Window

Sliding window is a dynamic extension of the two-pointer idea where the distance between pointers changes to maintain constraints like substring length or sum limits.

TitleSolutionAcceptDifficultyTopics
Solution60.9%Medium
Array, Greedy +1· 57 companies
15. 3SumVideo
Solution40.1%Medium
Array, Sorting +1· 57 companies
16. 3Sum ClosestVideo
Solution47.4%Medium
Array, Sorting +1· 11 companies
18. 4SumVideo
Solution42.0%Medium
Array, Sorting +1· 20 companies
Solution46.1%Medium
Array, Two Pointers· 31 companies
61. Rotate ListVideo
Solution43.1%Medium
Linked List, Two Pointers· 9 companies
75. Sort ColorsVideo
Solution69.9%Medium
Array, Sorting +1· 37 companies
Solution62.0%Medium
Linked List, Two Pointers· 5 companies
Solution59.3%Medium
Hash Table, Linked List +1· 13 companies
143. Reorder ListVideo
Solution66.6%Medium
Linked List, Recursion +2· 15 companies
148. Sort ListVideo
Solution65.2%Medium
Solution57.8%Medium
String, Two Pointers· 30 companies
161. One Edit DistanceVideoPremium
Solution34.4%Medium
String, Two Pointers· 8 companies
Solution46.8%Medium
String, Two Pointers· 11 companies
Solution66.1%Medium
Array, Binary Search +1· 16 companies
Solution56.6%Medium
String, Two Pointers· 4 companies
189. Rotate ArrayVideo
Solution45.3%Medium
Array, Math +1· 27 companies
244. Shortest Word Distance IIVideoPremium
Solution62.8%Medium
Array, Design +3· 4 companies
251. Flatten 2D VectorVideoPremium
Solution50.5%Medium
Array, Design +2· 4 companies
253. Meeting Rooms IIVideoPremium
Solution52.6%Medium
Array, Greedy +4· 42 companies
259. 3Sum SmallerVideoPremium
Solution51.4%Medium
Array, Binary Search +2· 7 companies
277. Find the CelebrityVideoPremium
Solution48.9%Medium
Graph, Interactive +1· 12 companies
Solution64.7%Medium
Array, Binary Search +2· 22 companies
360. Sort Transformed ArrayVideoPremium
Solution58.0%Medium
Array, Math +2· 3 companies
Solution60.9%Medium
String, Two Pointers· 41 companies
Solution38.3%Medium
Array, Hash Table +1· 4 companies
475. HeatersVideo
Solution42.9%Medium
Array, Binary Search +2· 12 companies
481. Magical StringVideo
Solution56.6%Medium
String, Two Pointers· 3 companies
Solution45.8%Medium
Array, Hash Table +3· 1 company
Solution46.3%Medium
Array, Binary Search +3· 8 companies
Solution35.2%Medium
Math, String +1· 11 companies
Solution49.8%Medium
Hash Table, Sliding Window +2· 16 companies
Solution38.7%Medium
Array, Greedy +4· 9 companies
Solution57.4%Medium
Array, Binary Search +3· 9 companies
Solution37.0%Medium
Binary Search, Math +1· 6 companies
Solution73.2%Medium
Dynamic Programming, String +1· 25 companies
Solution50.1%Medium
Array, Binary Search +4· 18 companies
723. Candy CrushVideoPremium
Solution77.6%Medium
Array, Matrix +2· 11 companies
Solution81.8%Medium
Greedy, Hash Table +2· 9 companies
Solution38.5%Medium
String, Two Pointers· 3 companies
Solution69.0%Medium
Array, Binary Search +3· 1 company
Solution46.8%Medium
Array, String +1· 2 companies
Solution49.9%Medium
Array, Binary Search +2· 3 companies
Solution56.4%Medium
Array, Binary Search +3· 5 companies
Showing 1–50 of 150

More about Two Pointers

The Two Pointers technique is a powerful algorithmic pattern used to process arrays or strings efficiently by maintaining two indices that move through the data structure. Instead of using nested loops, two pointers allow you to scan data from different directions or at different speeds, reducing time complexity from O(n²) to O(n) in many problems. This optimization is why the technique appears frequently in coding interviews and competitive programming.

Most Two Pointers problems are built on top of linear data structures such as Array or String. By carefully adjusting pointer positions—either moving toward each other or moving together—you can efficiently search for pairs, remove duplicates, reverse segments, or validate conditions across a sequence. Many interview problems that seem complex at first become straightforward once you recognize the underlying pointer pattern.

Two Pointers also connects naturally with other core DSA topics. For example, sorted arrays often combine the technique with Binary Search or Sorting. When the window between two pointers expands and contracts dynamically, the idea evolves into the popular Sliding Window technique. Some variations also use a Hash Table to track values while pointers move.

Common Two Pointers patterns include:

  • Opposite direction pointers: One pointer starts at the beginning and the other at the end (e.g., pair sum in a sorted array).
  • Fast and slow pointers: Two pointers move at different speeds to detect cycles or find middle elements.
  • Partitioning: Rearranging elements around a condition or pivot.
  • Deduplication: Removing duplicates from sorted arrays in-place.

If you're preparing for technical interviews, mastering this pattern is essential. Companies like Amazon, Google, and Meta regularly test it because it evaluates problem-solving ability, time complexity optimization, and familiarity with fundamental data structures. FleetCode provides with step-by-step explanations to help you recognize patterns quickly and solve interview questions with confidence.

Two Pointers: common questions

How many Two Pointers problems should I solve?

Start with basic pair-search and duplicate-removal questions, then move to harder problems like 3Sum, trapping water variants, and substring constraints.

What are the most common Two Pointers patterns?

The main patterns include opposite-direction pointers, fast and slow pointers, window expansion and contraction, partitioning arrays, and in-place deduplication. Recognizing which pattern applies to a problem is the key to solving it efficiently.

When should you use the Two Pointers technique?

Use Two Pointers when working with sequential data structures like arrays or strings where elements can be scanned linearly. It is especially effective when the input is sorted, when searching for pairs or ranges, or when maintaining a dynamic window of elements.

What is the best way to learn Two Pointers in DSA?

Begin with sorted-array pair problems to understand pointer movement. Then practice fast–slow pointer problems and transition to sliding window variants.

What are the best Two Pointers problems for interviews?

Classic interview problems include Two Sum in a sorted array, Container With Most Water, 3Sum, Remove Duplicates from Sorted Array, and Valid Palindrome. These questions test common patterns such as opposite-direction pointers and fast–slow pointers. Practicing 20–40 variations usually helps candidates recognize patterns quickly during interviews.

Is the Two Pointers technique important for FAANG interviews?

Yes. Two Pointers is a common interview pattern at companies like Amazon, Google, Meta, and Microsoft. It frequently appears in array and string problems because it demonstrates the ability to reduce time complexity from quadratic to linear.