Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container with Most Water Problem: #260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

naveen-sivaraj
Copy link

def max_area(height):
"""
Finds the maximum amount of water a container can store between two vertical lines.

Args:
    height (list of int): A list of non-negative integers representing the height of vertical lines.

Returns:
    int: The maximum area of water that can be contained.

Example:
    >>> max_area([1,8,6,2,5,4,8,3,7])
    49

Explanation:
    The maximum area is formed between the lines at indices 1 and 8 (height 8 and 7),
    giving an area of 49 (width = 7, height = 7).
"""
left = 0
right = len(height) - 1
max_area = 0

while left < right:

    width = right - left
    h = min(height[left], height[right])
    current_area = width * h
    max_area = max(max_area, current_area)

  
    if height[left] < height[right]:
        left += 1
    else:
        right -= 1

return max_area

if name == "main":
heights = [1, 8, 6, 2, 5, 4, 8, 3, 7]
print(f"The maximum water area is: {max_area(heights)}")

Copy link

vercel bot commented Oct 18, 2024

@naveen-sivaraj is attempting to deploy a commit to the mohamedsamara's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant