Container With the Most Water
Try to solve the Container With the Most Water problem.
We'll cover the following
Statement#
You’re given an integer array height of length , and there are vertical lines drawn such that the two endpoints of the line are and (, 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:
-
height.length -
-
height[i]
Examples#
1 of 2
2 of 2
Understand the problem#
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Container With the Most Water
What is the maximum amount of water a container can store if we have the following input?
height = [1, 1]
1
2
0
Try it yourself#
Implement your solution in the following coding playground.
An optimal solution to this problem runs in O(n) time and takes O(1) space.
You might want to go over the Two Pointers pattern again.
Solution: Valid Palindrome
Solution: Container With the Most Water