Container With Most Water: the skills you need first
Updated
LeetCode · medium · two pointers. Area is limited by the shorter wall. Move that end; the other cannot help yet.
Skills this problem builds on
Stuck on Container With Most Water? It is usually one of these. Get each one solid and the solution stops being a trick.
- Close the gap from both ends
Closing the gap moves both ends inward in one step: L += 1 and R -= 1. The unprocessed slice loses one index on each side.
- Decide which end to advance
The decision reads a[L] and a[R], usually their sum. Move the end whose value you have consumed. Do not move both unless the algorithm says so.
- Compare values at both ends
check which ones you have 10 minutes, free, no account.
More two pointers problems
- Valid Palindromeeasy
- Two Sum IImedium
- 3Summedium