Skip to content

Commit

Permalink
ADD: Continer with most water problem
Browse files Browse the repository at this point in the history
  • Loading branch information
InclinedScorpio committed Sep 29, 2024
1 parent cff6431 commit 8972fe9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions XDaysChallenge/90DaysChallenge/Day7/container_with_most_water.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// https://leetcode.com/problems/container-with-most-water/description/

/**
* Problem requires understanding of two pointer approach
*/
class Solution {
public:
int maxArea(vector<int>& height) {
int currMax=0;
for(int i=0, j=height.size()-1;i<j;) {
currMax = max(currMax, min(height[i], height[j])*(j-i));
if(height[i]>height[j]) --j;
else ++i;
}
return currMax;
}
};

0 comments on commit 8972fe9

Please sign in to comment.