Math Fundamentals18 sections · 814 units
Open in Course

Container - The Formula

Maximizing area

The area formula is: A=(ji)×min(hi,hj)A = (j - i) \times \min(h_i, h_j) where hi=height[i]h_i = height[i] and hj=height[j]h_j = height[j].

The width (ji)(j - i) is the distance between lines. The height is limited by the shorter line (water spills over the shorter side).

You want to maximize this product. The brute force approach checks all pairs in O(n2)O(n^2) time. Can you do better?