Skip to content

Instantly share code, notes, and snippets.

@SuryaPratapK
Created June 22, 2024 19:50
Show Gist options
  • Save SuryaPratapK/d676a530199642eddeba518cf120a880 to your computer and use it in GitHub Desktop.
Save SuryaPratapK/d676a530199642eddeba518cf120a880 to your computer and use it in GitHub Desktop.
class Solution {
public:
int maxArea(vector<int>& height) {
int left=0, right=height.size()-1;
int max_area = 0;
int curr_area;
while(left < right)
{
curr_area = (right-left)*min(height[left], height[right]);
max_area = max_area < curr_area ? curr_area: max_area;
height[left] > height[right] ? --right: ++left;
}
return max_area;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment