Problem
Ask
Submissions

Problem: Container with Most Water

Medium
30 min
Explore how to identify two lines in an array that form a container holding the most water, focusing on algorithm efficiency and optimal space-time tradeoffs. This lesson helps you implement and understand a linear-time solution that maximizes container capacity without slanting.

Statement

You’re given an integer array height of length nn, and there are nn vertical lines drawn such that the two endpoints of the ithi^{th} line are (i,0)(i, 0) and (ii, height[i]).

Find two lines from the input array that, together with the x-axis, form a container that holds as much water as possible. Return the maximum amount of water a container can store.

Note: You may not slant the container.

Constraints:

  • n=n = height.length

  • 22 \leq nn 103\leq 10^3

  • 00 \leq height[i] 103\leq 10^3

Problem
Ask
Submissions

Problem: Container with Most Water

Medium
30 min
Explore how to identify two lines in an array that form a container holding the most water, focusing on algorithm efficiency and optimal space-time tradeoffs. This lesson helps you implement and understand a linear-time solution that maximizes container capacity without slanting.

Statement

You’re given an integer array height of length nn, and there are nn vertical lines drawn such that the two endpoints of the ithi^{th} line are (i,0)(i, 0) and (ii, height[i]).

Find two lines from the input array that, together with the x-axis, form a container that holds as much water as possible. Return the maximum amount of water a container can store.

Note: You may not slant the container.

Constraints:

  • n=n = height.length

  • 22 \leq nn 103\leq 10^3

  • 00 \leq height[i] 103\leq 10^3