Two Pointers
Scan a sorted array or string from both ends at once to find pairs, remove duplicates, or reverse data in O(n).
Two Pointers Practice Problems
Easy
12 problems- 11easy
Valid Palindrome
Check whether a string reads the same forwards and backwards, ignoring case and punctuation.
- 12easy
Merge Sorted Array
Merge two sorted arrays into one sorted array in place.
- 13easy
Remove Duplicates from Sorted Array
Remove duplicate values from a sorted array in place and return the new length.
- 14easy
Move Zeroes
Move every zero in an array to the end while keeping the other numbers in order.
- 21easy
Squares of a Sorted Array
Square every value in a sorted array and return the result sorted, without re-sorting.
- 22easy
Reverse String
Reverse an array of characters in place.
- 23easy
Is Subsequence
Check whether one string is a subsequence of another.
- 24easy
Backspace String Compare
Check whether two strings are equal once # is treated as a backspace in each.
- 200easy
Palindrome Linked List
Check whether a linked list reads the same forwards and backwards.
- 201easy
Intersection of Two Arrays II
Find every value that appears in both arrays, as many times as it appears in both.
- 202easy
Reverse Vowels of a String
Reverse only the vowels of a string, leaving every other character in place.
- 203easy
Sort Array By Parity
Rearrange an array so every even value comes before every odd value.
Medium
17 problems- 15medium
Two Sum II - Input Array Is Sorted
Find two numbers in a sorted array that add up to a target value.
- 16medium
3Sum
Find every unique triplet of numbers in an array that adds up to zero.
- 17medium
Container With Most Water
Choose two lines from a list of heights that hold the most water between them.
- 18medium
Sort Colors
Sort an array of three distinct values in place in a single pass.
- 19medium
4Sum
Find every unique quadruplet of numbers in an array that adds up to a target value.
- 25medium
3Sum Closest
Find the triplet in an array whose sum is closest to a target value.
- 26medium
Remove Duplicates from Sorted Array II
Remove duplicates in place from a sorted array so each value appears at most twice.
- 27medium
Boats to Save People
Pair the heaviest and lightest people to minimize the number of boats needed within a weight limit.
- 28medium
Linked List Cycle
Detect whether a linked list has a cycle using a fast and slow pointer.
- 29medium
Middle of the Linked List
Find the middle node of a linked list in one pass with a fast and slow pointer.
- 30medium
Remove Nth Node From End of List
Remove the nth node from the end of a linked list in one pass using two pointers.
- 204medium
Sort Array By Parity II
Rearrange an array so every even index holds an even value and every odd index holds an odd value.
- 205medium
Rotate Array
Rotate an array to the right by k steps in place.
- 206medium
Reverse Words in a String
Reverse the order of the words in a sentence while collapsing extra whitespace.
- 207medium
Interval List Intersections
Find every overlapping range between two sorted lists of intervals.
- 208medium
Reorder List
Reorder a linked list by weaving its first half with its reversed second half.
- 209medium
Next Permutation
Rearrange an array into the next lexicographically greater arrangement in place.
Hard
1 problemsRelated concepts
| Topic | Description |
|---|---|
| Sliding Window | Solve fixed-window problems: maximum sum of k elements, moving averages, and O(n) updates as the window slides. |
| Merge Sort | Split the list in half, sort each half, then merge them back together in order, giving reliable O(n log n) time. |
| Linked Lists | Nodes linked by pointers — insert and delete without shifting a contiguous block. |
| Arrays | Ordered indexable collection for O(1) access by position. |
| Binary Search | Cut a sorted range in half on every step to find a value or boundary in O(log n) instead of checking one by one. |
| Depth-First Search | Explore as far as possible down one path before backtracking, used to walk trees, graphs, and grids. |