From 1705e6776e5be3b5875b3f67a3885e920f4b4c7c Mon Sep 17 00:00:00 2001 From: Satyam Singh <111181853+Satyam-Singh-01@users.noreply.github.com> Date: Sun, 5 Oct 2025 01:23:38 +0530 Subject: [PATCH] Create Container With Most Water You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that you may not slant the container. --- .../Problems/Python/Container With Most Water | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LeetCode/Problems/Python/Container With Most Water diff --git a/LeetCode/Problems/Python/Container With Most Water b/LeetCode/Problems/Python/Container With Most Water new file mode 100644 index 00000000..81a8b698 --- /dev/null +++ b/LeetCode/Problems/Python/Container With Most Water @@ -0,0 +1,21 @@ +class Solution { +public: + int maxArea(vector& height) { + int left = 0; + int right = height.size() - 1; + int maxArea = 0; + + while (left < right) { + int currentArea = min(height[left], height[right]) * (right - left); + maxArea = max(maxArea, currentArea); + + if (height[left] < height[right]) { + left++; + } else { + right--; + } + } + + return maxArea; + } +};