You are coding as a Guest. Sign in with your RoleNest account to permanently track your streak, earn XP, and climb the Campus Leaderboard!
Sign In with RoleNestProblem Set
🔥Container With Most Water: Maximum AreaMedium
MediumTwo Pointers•Acceptance: 55.3%
Container With Most Water: Maximum Area
Real-World Engineering Context
Resource allocation in cloud server auto-scaling bandwidth envelopes and histogram capacity planning.
You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `i`th 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.
Sample Test Cases
Input: [[1,8,6,2,5,4,8,3,7]]
Expected: 49
Input: [[1,1]]
Expected: 1
Input: [[4,3,2,1,4]]
Expected: 16
Constraints
- n == height.length
- 2 <= n <= 10^5
- 0 <= height[i] <= 10^4
Language:
Ready to test. Click Run Code or Submit Solution to run test cases in isolated browser sandbox.