Problem 12 of 75

Container With Most Water

MediumNot solved yetInterview me on this
Before you code · which pattern fits?

The problem

You are given an integer array height of length n. There are n vertical lines; the i-th line goes from (i, 0) to (i, height[i]). Find two lines that, together with the x-axis, form a container that holds the most water. Return the maximum amount of water it can store.

[1,8,6,2,5,4,8,3,7] → 49

Your solution runs against 2 unit tests, including edge and large-value cases.

Loading...

Test console · 2 unit tests

Submit your code to run it against all 2 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.

Hint

Reference solution

Video explanation

Container With Most Water, explainedNeetCode
GO DEEPER

The full interview treatment: the conversation, why the approach works, and step-by-step visuals.