1οΈβ£ Core Idea
- Use 2 pointers (indices) instead of 1
- Move them in coordination
- Goal β reduce time, avoid extra space
3οΈβ£ When to Think Two Pointer π
βοΈ Strong Signals
- ONLY ON β Array / Linked List
- Sorted OR can be sorted
- Find:
- Pair / Triplet / Quadruple
- Operations:
- Merge
- Remove duplicates
- Rearrange elements
- Constraint:
- If No extra space allowed
- Linked List:
- Cycle detection
- Time Complaxcity:
| Approach | Time | Space | Notes |
|---|---|---|---|
| Brute Force | O(nΒ²) | O(1) | Simple but slow |
| HashMap | O(n) | O(n) | Fast but extra space |
| Two Pointer | O(n log n) - shorting | O(1) | Optimal space |
4οΈβ£ Types of Two Pointer Problems (Important)
1. π Opposite Ends (Most Common)

One pointer at start
s, one at endeMove towards centerwhile (s < e)
π Used in:
- Pair sum
- Palindrome
- Sorting / rearranging
Example Problems
- 1. Two Sum
- 3Sum / 4Sum
- Container with most water
- Trapping rain water
- Reverse string/Array
2. π’ Slow & Fast Pointer
Next type is using two pointers with different speed of movement. Typically they starts from the left end, then the
fast pointeradvances fast and give some feedback to theslow pointerand do some calculation.

π Used in:
- Linked list problems
- Cycle detection
Example Problems
- Find the middle of a linked list
- Remove Dublicate from sorted LL - 3. Slow Fast ptr
- Linked List Cycle
- Find duplicate number
- Remove nth node
3. π Two Arrays / Merging
In this category, you will be given 2 arrays or lists, then have to process them with individual pointers.

π Used in:
- Merge sorted arrays
- Intersection problems
Example Problems
- Merge Sorted Array
- Intersection of arrays
- strstr()
4. βοΈ Split & Merge
The last one is similiar to previous category but there is one thing is added. First, you need to split the given list into 2 separate lists and then do two pointers approach to merge or unify them. There arenβt many tasks here.
