Skip to content

Commit

Permalink
Day 21: Q2 - Container With Most Water #421 cpp code added by Akansha77
Browse files Browse the repository at this point in the history
  • Loading branch information
Akansha77 committed Jan 23, 2024
1 parent 38bac8d commit 3a8c6cd
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 3a8c6cd

Please sign in to comment.