Skip to content

Commit

Permalink
Merge pull request #526 from Akansha77/Akansha_75
Browse files Browse the repository at this point in the history
Day 21: Q2 - Container With Most Water #421 cpp code added.
  • Loading branch information
bh-g authored Jan 23, 2024
2 parents 8ffe8c1 + 3a8c6cd commit d9f45c6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Day-21/q2 : Container With Most Water/Akansha--C.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Solution {
public:
int maxArea(vector<int>& height) {
int a=height.size();
int i=0;
int j=a-1;
int z=a-1;
int maxElement;
vector <int> b;
while(i<j){
int x=min(height[i],height[j]);
int pro=x*z;
b.push_back(pro);
if(x==height[i]){
i++;
}
else if(height[i]==height[j]){
i++;
if(i>a-1){
break;
}
}
else{
j--;
}
z--;
}
for (int y = 0; y< a-1; ++y) {
if (b[y] > maxElement) {
maxElement = b[y];
}
}
return maxElement;
}
};

0 comments on commit d9f45c6

Please sign in to comment.