Skip to content

Conversation

amrit-GH23
Copy link
Contributor

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 ?

  • [ ✅] Added problem & solution under correct topic.
  • [✅ ] Specified Space & Time complexity.
  • [✅ ] Specified difficulty level, tag & Note(if any).

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.

  • [ ✅] Test A : testcase : [1,8,6,2,5,4,8,3,7], [1,1]
  • [✅ ] Test B : Submitted on leetcode (Beats 100% user)

Make sure all below guidelines are followed else PR will get Reject:

  • [ ✅] My code follows the style guidelines of this project
  • [ ✅] I have performed a self-review of my own code
  • ✅[ ] I have commented my code so that it is easy to understand
  • [✅ ] I have made corresponding changes to the documentation
  • [ ✅] My changes generate no new warnings
  • [✅ ] Any dependent changes have been merged and published in downstream modules

Copy link

welcome bot commented Mar 16, 2025

I can tell this is your first pull request! Thank you I'm so honored. 🎉🎉🎉 I'll take a look at it ASAP!

@amrit-GH23 amrit-GH23 marked this pull request as draft March 16, 2025 06:51
@amrit-GH23 amrit-GH23 marked this pull request as ready for review March 16, 2025 06:52
@amrit-GH23
Copy link
Contributor Author

Hi, I recently submitted PR #[501], which addresses solves leetcode problem Container With Most Water (cpp) . Could someone review it when possible? Thanks!"

@GouravRusiya30
Copy link
Member

Can you check README again, we already have this problem's solution. You just have to edit your solutions link there.

@amrit-GH23
Copy link
Contributor Author

I have updated the readme.md file and added the link with the problem

Copy link
Member

@GouravRusiya30 GouravRusiya30 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@GouravRusiya30 GouravRusiya30 merged commit 214fdad into codedecks-in:master Mar 18, 2025
Copy link

welcome bot commented Mar 18, 2025

Your code looks great! Congrats, I've gone ahead and merged your first pull request! Keep it up! alt text

@amrit-GH23
Copy link
Contributor Author

Thanks for merging! Happy to contribute.

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.

2 participants