Skip to content
core-pattern

Two Pointers

Coordinate two indices to shrink the search space in arrays, strings, and partitions.

Problems

Problems in Two Pointers

Practice problems that share this primary solution pattern and compare the clues that reveal it.

Close-up of hands coding on a laptop, showcasing software development in action.
intermediate
10 min read

3Sum

A reliable 3Sum solution comes from turning a cubic search into a sequence of sorted two-sum scans—and proving why each pointer move is safe.

View solution
Professional team discussing analytics and brainstorming ideas in a meeting room.
intermediate
12 min read

3Sum Closest

The target does not identify the winning triplet. It tells each pointer which direction is still worth exploring.

View solution
Visual abstraction of neural networks in AI technology, featuring data flow and algorithms.
advanced
13 min read

4Sum

Four choices suggest an O(n^4) search. Sorting changes the last two choices into a controlled walk.

View solution
Laptop on green grass in sunlight. Ideal for remote work and technology themes.
intermediate
9 min read

Container With Most Water

The hard part is not calculating width × shorter_height. It is proving why one whole family of pairs can be discarded without checking them.

View solution
Professional business meeting with presentation and data analytics on whiteboard.
beginner
8 min read

Remove Element

The array is not shortened. The judge inspects only a prefix, so the job is to compact the values you keep into that prefix and return its length.

View solution
Close-up of a digital interface showcasing futuristic graphs and data analytics in low light.
beginner
8 min read

Merge Sorted Array

A left-to-right merge can overwrite values in nums1 before you have compared them. The reliable Merge Sorted Array solution uses backward two pointers:…

View solution
Aerial photograph of a tractor working in a vast, vibrant green field captured from above.
intermediate
11 min read

Sort Colors

The trap in the Sort Colors solution is assuming that “only three values” makes the problem trivial. Counting works. The interview version asks you to see…

View solution
Skilled craftsman sharpens a blade on a grinding wheel, creating sparks in a workshop.
advanced
12 min read

Trapping Rain Water

The picture suggests moving inward from both ends. The proof requires more: finalize only the side whose limiting boundary is already certified.

View solution