Container with most water | Leetcode 11


What is the best possiblity for a container to have maximum water?

The best possiblity will be when, you have the widest width(w) and highest height(h), right?

So the maximum width we can have is length of the array(n). Now we have to find the height. We can do that using two pointers(left and right).

left => left most element of the array.

right => right most element of the array.

we will compare both the elements, and whichever is smaller, we will move that pointer since we want to find the best height for the container. While doing so we keep calculating the current area and updating the ans.

Here is the code.

Thank you




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Introduction To Python

How to Create and Deploy a FastAPI Application Using Poetry and Serverless

Facilitating a Service Blueprinting Workshop — as colorful as the artifact itself


42 Silicon Valley: An Exercise In Learning Failure

Hello Family Noodle’s Master and CZ Kitchen 🍜🍜🍜

How I prepared and cleared the PSM1 exam

A Post-Agile World —How we can apply the lessons of the manifesto to a modern Product Engineering…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pushpam Kumar

Pushpam Kumar

More from Medium

A Brief about Floyd Cycle Detection algorithm

Prim’s Algorithm

Why do array indexes mostly start at 0?