FastPrepContainer With Most Water

Container With Most Water

EPAM logoEPAM● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Given an array height, where height[i] is the height of a vertical line at position i, choose two lines that together with the horizontal axis form a container.

Return the maximum amount of water the container can hold. The area between indices left and right is (right - left) * min(height[left], height[right]).

Function

maxArea(height: int[]) → int

Examples

Example 1

height = [1,8,6,2,5,4,8,3,7]return = 49

Indices 1 and 8 have limiting height 7 and width 7.

Example 2

height = [1,1]return = 1

The only pair has width and height 1.

Constraints

  • 2 <= height.length <= 100000.
  • 0 <= height[i] <= 10000.
  • The maximum area fits in a signed 32-bit integer.

Source note: Author-written prompt excerpt retained for source fidelity.

More EPAM problems

See EPAM hiring insights
public int maxArea(int[] height) {
    // Write your code here.
}
height[1,8,6,2,5,4,8,3,7]
expected49
Checking account…