Container with most water

Problem Description

Solution Explanation

Implementation

class Solution:
	def max(self, height: List[int]) -> int:
		res = 0
		for lp in range(len(height)):
			for rp in range(lp+1, len(height)):
			# Calculation used here is to find area of rectangle
				area = (rp-lp)*min(height[rp], height[lp])
				res = max(area, res)
		return res
class Solution:
    def maxArea(self, height: List[int]) -> int:
        res = 0
        # We set the lp to start of array and rp to end of array
        lp, rp = 0, len(height) - 1
        # Check to ensure lp is less than rp for a valid container
        while lp < rp:
            area = (rp - lp) * min(height[rp], height[lp])
            # Update res if area bigger or just leave it at current res
            res = max(res, area)
  
            if height[lp] < height[rp]:
            # Update lp if it is less than rp
                lp+=1
            else:
            # Update rp if it is less than lp
            # or
            # Update rp if lp=rp
                rp -= 1
        return res