[InterviewBit] Container With Most Water

Container With Most Water

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
int Solution::maxArea(vector<int> &A) {
int l = 0, r = A.size() - 1;
int res = 0;
while(l < r) {
res = max(res, (r - l) * min(A[l], A[r]));
if(A[l] < A[r]) l++;
else r--;
}
return res;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/09/27/PS/interviewbit/container-with-most-water/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.