From 7a847c1d00587cd73fbd7081830ff27b166d6147 Mon Sep 17 00:00:00 2001 From: kkomalk <71619994+kkomalk@users.noreply.github.com> Date: Sun, 31 Oct 2021 19:01:59 +0530 Subject: [PATCH] Create ContainerWithMostWater.cpp Solution of Container with most water problem --- cpp/ContainerWithMostWater.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 cpp/ContainerWithMostWater.cpp 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; +}