🧠 Before you code — what pattern fits?
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
🎬 Video explanation · NeetCode
Your solution runs against 2 unit tests, including edge and large-value cases.
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.
Want the full interview treatment — the conversation, the why, and step-by-step visuals? Read the deep dive →