DEV Community

JOY SINHA
JOY SINHA

Posted on

11. Container With Most Water [Leetcode ]

Optimized Python 3 Solution for Container with most water problem.
I am using two pointer shifting technique to solve it so that we can reduce time complexity of the solution.

CODE:-

class Solution:
def maxArea(self, height: List[int]) -> int:
maxArea = 0
p1 = 0
p2 = len(height)-1
while(p1<=p2):
maxArea = max(maxArea,min(height[p1],height[p2])*(p2-p1))
if(height[p1]<height[p2]):
p1=p1+1
else:
p2=p2-1
return maxArea

Top comments (0)

Image of Bright Data

Ensure Data Quality Across Sources – Manage and normalize data effortlessly.

Maintain high-quality, consistent data across multiple sources with our efficient data management tools.

Manage Data

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay