Time Complexity
O(n)
Two Pointers is a technique where two indices move through a data structure (usually an array) to solve problems efficiently.
Common patterns:
- Left & Right: start from both ends, move inward
- Slow & Fast: both start from beginning at different speeds
Time Complexity: O(n) — each pointer moves at most n times
Space Complexity: O(1) — only two variables
Classic problems:
- Two Sum (sorted array)
- Container with most water
- Remove duplicates in-place
- Palindrome checking
- Linked list cycle detection (slow/fast)
Related algorithms
Frequently asked questions
- What is Two Pointers?
- Two Pointers is a technique where two indices move through a data structure (usually an array) to solve problems efficiently.
- What is the complexity of Two Pointers?
- Time (average): O(n) · Space: O(1)
- Who is this Two Pointers visualizer for?
- The Two Pointers visualization targets intermediate-level learners in the Concepts category. Useful for students, interview prep, and hands-on review.
- What algorithms are related to Two Pointers?
- In the same category (Concepts) you can explore: Big O Notation, Recursion, Sliding Window. Each has an interactive visualization.