added problem number 011 (container-with-most-water)(https://leetcode.com/problems/container-with-most-water/) #501
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Template
Description
Intuition
The problem is about finding two vertical lines that can contain the most water. The key observation is that the area is determined by the smaller height among the two chosen lines and the distance between them.
To maximize the area, we should consider the widest possible container first and then move the pointers inward based on which height is smaller.
Approach
Two Pointers Approach:
We start with two pointers:
i at the leftmost index (0).
j at the rightmost index (n-1).
Compute the current area using:
area=(j−i)×min(height[𝑖],height[𝑗])
area=(j−i)×min(height[i],height[j])
Update the maximum area if the new area is greater.
Move the pointer that has the smaller height:
If height[i] < height[j], increase i (move right).
Otherwise, decrease j (move left).
Repeat the process until i < j.
This approach ensures that we explore all possible containers efficiently.
Put check marks:
Have you made changes in README file ?
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Please also note any relevant details for your test configuration.
Make sure all below guidelines are followed else PR will get Reject: