11.Container With Most Water
Find two lines, which, together with the x-axis forms a container, such that the container contains the most water
Last updated
Find two lines, which, together with the x-axis forms a container, such that the container contains the most water
Last updated
Time Complexity: O(n^2)
To maximize the area, we need to consider the area between the lines of larger lengths. If we try to move the pointer at the longer line inwards, we won't gain any increase in area, since it is limited by the shorter line. But moving the shorter line's pointer we can have an increase in area.
Time complexity : O(n)