Container With Most Water

 https://www.interviewbit.com/old/problems/container-with-most-water/

class Solution {
public:
    int maxArea(vector<int>& A) {
    int l=0;
    int r=A.size()-1;
    int area=0;
    while(l<r)
    {
        area=max(area,min(A[l],A[r])*(r-l));
        if(A[l]<A[r])
             l++;
        else
             r--;
    }
    return area;
    }
};

Comments

Popular posts from this blog

Perfect Peak of Array

Is Rectangle?

Sort array with squares!