31. Container With Most Water
β GFG solution to the Container With Most Water problem: find maximum water area between two vertical lines using optimal two-pointer technique. π
π§© Problem Description
π Examples
Example 1
Input: arr[] = [1, 5, 4, 3]
Output: 6
Explanation: Lines at indices 1 and 3 with heights 5 and 3 are 2 distance apart.
Base = 2, Height = min(5, 3) = 3. Total area = 3 Γ 2 = 6.Example 2
Input: arr[] = [3, 1, 2, 4, 5]
Output: 12
Explanation: Lines at indices 0 and 4 with heights 3 and 5 are 4 distance apart.
Base = 4, Height = min(3, 5) = 3. Total area = 3 Γ 4 = 12.Example 3
π Constraints
β
My Approach
Two Pointers + Greedy Algorithm
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated