Skip to content

Prem-333/Container-With-Most-Water

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Your code implements the Container With Most Water problem (LeetCode #11) using the Two-Pointer Technique.

Here’s the algorithm:

Algorithm for maxArea Start

Initialize:

l = 0 (left pointer)

r = heightSize - 1 (right pointer)

ans = 0 (max area so far)

While l < r:

Compute t = min(height[l], height[r]) * (r - l) (area between two lines)

Update ans = max(ans, t)

If height[l] < height[r], increment l (l++)

Else, decrement r (r--)

Return ans

End

Why It Works Start with the widest container (l=0, r=n-1)

Move the pointer pointing to the shorter line inward, because width decreases anyway, so to increase area, we need a taller height.

About

dasshdfkglh

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors