Loading…
Loading…
Given an array height where height[i] is the height of a vertical line at position i, find two lines that together with the x-axis form a container holding the most water. Return the maximum area.
Input: 1 8 6 2 5 4 8 3 7
Output: 49 (between index 1, height 8, and index 8, height 7: width 7 × min(8,7) = 49)
Start pointers at both ends. The area is limited by the shorter line, so always move the pointer at the shorter line inward — moving the taller one can never increase the area.
Input (stdin)
Output
Input (stdin)
Output
Sign in to track solved problems and earn XP.
No discussions yet
Be the first to start a conversation.