Two pointers
A technique that walks a list with 2 indexes at once, for example one from each end, moving them by a rule until they meet.
Example
For the largest container in a list of 9 heights, i starts at 0 and j at 8, and the shorter one moves: 8 steps instead of 36 pairs.
Test yourself: Two pointers
Largest container
The capacity of 2 boards is min(ht[i], ht[j]) × (___).
The shorter sets the height and the distance the width: boards of height 8 and 7, 7 apart, give 7 × 7 = 49.
Largest container
In [1, 8] with ht[1] = 8 and ht[8] = 7, the capacity is 49 and ___ moves.
Board j (7) is the shorter: j becomes 7, and cap[1, 7] = min(8, 3) × 6 = 18.
0/2
â–¶ Play