Dashboard
LC #11

Container With Most Water

Pattern · ?AmazonGoogleMetaBloomberg

Problem

Find two lines that together with the x-axis form a container that holds the most water.

Constraints

  • 2 ≤ n ≤ 10⁵
  • 0 ≤ height[i] ≤ 10⁴

Example

Input
height = [1, 8, 6, 2, 5, 4, 8, 3, 7]
Output
49
Why
Lines at index 1 (h=8) and 8 (h=7): min(8,7) × (8−1) = 7 × 7 = 49

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗