diff --git a/cpp/ContainerWithMostWater.cpp b/cpp/ContainerWithMostWater.cpp new file mode 100644 index 0000000..ec4f9fa --- /dev/null +++ b/cpp/ContainerWithMostWater.cpp @@ -0,0 +1,18 @@ +int Solution::maxArea(vector &A) { + int l = 0, r = A.size()-1; + int ans = INT_MIN; + + if(r == 0) return 0; + + while(l < r){ + ans = max(ans, (r-l)*min(A[r], A[l])); + if(A[r] < A[l]){ + r--; + } + else{ + l++; + } + } + + return ans; +}