Notice Period

Widest Tank

medium

A vineyard has a row of vertical posts of varying heights, and the owner wants to stretch a waterproof liner between exactly two posts to make an open-top water tank. The tank's capacity is its width (distance between the chosen posts) times the height of the shorter post — water spills over the lower rim.

Given posts where posts[i] is the height of the post at position i (adjacent positions are distance 1 apart), return the maximum capacity any pair of posts can hold.

Example 1
in posts = [1, 8, 6, 2, 5, 4, 8, 3, 7]
out 49
Posts at positions 1 and 8 (heights 8 and 7): width 7 × min(8, 7) = 49.
Example 2
in posts = [1, 1]
out 1
Width 1 × height 1.
Constraints
  • · 2 <= len(posts) <= 10^5
  • · 0 <= posts[i] <= 10^4
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.