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
DAILY PROBLEM OF THE DAY+50 XP • Daily Streak
Solve today's challenge or tackle one of the 3 Super Hard challenges for +150 XP.
MediumTwo Pointers•Acceptance: 55.3%
Container With Most Water: Maximum Area
Targeted in FAANG & Tech OA:GoogleAmazonMicrosoftSwiggy
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
Recruiter Fast-Track ReferralVerified Candidate
Direct pipeline to Google, Amazon, Microsoft, Swiggy, & Uber recruiters
Top DevScore profiles bypass resume screening filters. Every verified problem solve writes authentic proof-of-work to your profile and dispatches you directly into employer inboxes on RoleNest.
Explore 5,000+ Direct ATS Openings on RoleNest ↗✓ Direct Referral Active
Language:
Ready to test. Click Run Code or Submit Solution to run test cases in isolated browser sandbox.