<aside>
This section is part of the 5-hour LeetCode DSA Foundations course by Mukul Raina
Section 6: Two Pointers
Two pointers is a technique where two index variables traverse a data structure in a coordinated way, eliminating the need for nested loops. Instead of checking every possible pair with O(n^2) brute force, two pointers exploits structure in the input (usually sorted order) to find the answer in O(n).
The core idea: if the input has some ordering property, you do not need to check every combination. You can make an informed decision about which pointer to move, discarding large portions of the search space with each step.
What We’ll Cover:
Where This Fits in the Course:
Two pointers extends the array techniques from Section 3 and often serves as an alternative to the hash map approach from Section 5. The difference: hash maps trade O(n) space for O(1) lookups on unsorted input, while two pointers achieves O(n) time with O(1) space on sorted input. Sliding window (Section 7) is a specialized form of same-direction two pointers applied to subarray optimization problems. Binary search (Section 8) also operates on sorted input but solves a different class of problems (finding a specific element or boundary rather than finding pairs).
<aside>
Mukul Raina | youtube.com/@mukulraina | linkedin.com/in/mukulraina
</aside>