Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Container with Most Water
Array Alchemist
Jul 31, 2024
82 views
Container with Most Water
Blind 75. Array Question
You are given an integer array
height
of lengthn
. There aren
vertical lines drawn such that the two endpoints of theith
line are(i, 0)
and(i, height[i])
.Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return the maximum amount of water a container can store.
Notice that you may not slant the container.
Real world applications:
These are some real world problems that can be solved using the solution of container with max water. Let's see how we can solve it?
What are obvious conclusions given from question?
sliding window technique:
This is how this problem can be solved.
Complexity:
Time complexity is O(n), as we are iterating through the array once
Space complexity is O(1), as we don't have any array or storage