MediumVery High Frequency30 min
Two Pointers
Solve pair and subarray problems in O(n) by managing two indices simultaneously.
Use two indices moving toward each other (or same direction) to solve pair/subarray problems in O(n) instead of O(n²).
The Two Pointers Technique
Operations — Step by Step
Two Sum (sorted)
O(n)Requires sorted array. Converge from both ends.Step-by-step1 / 4
L=0, R=3. Target = 9
Left at val=2, Right at val=15. Compute sum = 2+15 = 17.