Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Maximize Container Capacity with Limited Heights

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Maximize Container Capacity with Limited Heights. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given an array of integers representing the heights of vertical containers, calculate the maximum amount of water that can be contained between them. The water can only be trapped if there are taller containers on both sides. The width of each container is 1.

Constraints

  • 2 <= heights.length <= 10^5
  • 0 <= heights[i] <= 10^4

Function Signature

def max_area(heights: list[int]) -> int:
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output