Two Pointers
Retrieval: pointers against hashing
Two problems rebuilt cold, plus the discrimination that decides which tool a new problem wants.
You now have two ways to find a pair with a property: a hash map from Unit 1, and converging pointers from this unit. They are not interchangeable, and picking wrong is the most common way this material fails to transfer.
Key idea
The deciding questions
Is the input sorted, or are you allowed to sort it? Two pointers need order. A hash map does not care.
Do you need the original positions? Sorting destroys them unless you carry them along. A hash map keeps them for free.
Is extra memory allowed? Two pointers are O(1) space. A hash map is O(n).
Sorted input with an O(1) space requirement means two pointers. Unsorted input where positions matter means a hash map. When both work, say so and pick one out loud.
Which tool fits?
An unsorted array of prices, and you must return the positions of two prices summing to a budget. The array can hold a million entries. Which approach fits best?
3Sum, from scratch
You have solved this one before. Rebuild it from scratch without looking at your old submission. If the approach does not come back within a few minutes, that is the signal that it needs another pass.
Longest Consecutive Sequence, from scratch
You have solved this one before. Rebuild it from scratch without looking at your old submission. If the approach does not come back within a few minutes, that is the signal that it needs another pass.