Skip to content

Commit

Permalink
added container with most water question
Browse files Browse the repository at this point in the history
  • Loading branch information
b-izad committed Jun 16, 2023
1 parent cc78f42 commit a5d57ca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions Twopointer/11. Container With Most Water.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'''11. Container With Most Water
Medium
You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return the maximum amount of water a container can store.
Notice that you may not slant the container.'''

class Solution:
def maxArea(self, height):

maxValue = 0
left = 0
right = len(height) - 1

while left < right:
currentArea = min(height[left], height[right]) * (right - left)
maxValue = max(maxValue, currentArea)

if height[left] < height[right]:
left += 1
else:
right -= 1

return maxValue
2 changes: 1 addition & 1 deletion Twopointer/26. Remove Duplicates from Sorted Array.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Change the array nums such that the first k elements of nums contain the unique elements in the order they were present in nums initially. The remaining elements of nums are not important as well as the size of nums.
Return k.'''

def removeDuplicates(self, nums: List[int]) -> int:
def removeDuplicates(self, nums: List[int]) -> int:
if len(nums)==0:
return 0
i = 0
Expand Down

0 comments on commit a5d57ca

Please sign in to comment.