← Pointer Manipulation

Micro-Drill #123 — Container with most water

Pointer Manipulation Target: 15s

Greedy two-pointer moves the shorter wall inward. O(n) time, O(1) space.

l, r = 0, len(h)-1
mx = 0
while l < r:
    mx = max(mx, min(h[l], h[r]) * (r - l))
    if h[l] < h[r]: l += 1
    else: r -= 1

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #122 Micro #124 →