From b612420597656ee0e20a84de7377517741eb40de Mon Sep 17 00:00:00 2001 From: ankitakulkarnigit Date: Sat, 21 Mar 2026 19:49:28 -0700 Subject: [PATCH 1/3] container most water --- Sample.java | 7 ------- Sample.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) delete mode 100644 Sample.java create mode 100644 Sample.py diff --git a/Sample.java b/Sample.java deleted file mode 100644 index f5c45b5f..00000000 --- a/Sample.java +++ /dev/null @@ -1,7 +0,0 @@ -// Time Complexity : -// Space Complexity : -// Did this code successfully run on Leetcode : -// Any problem you faced while coding this : - - -// Your code here along with comments explaining your approach \ No newline at end of file diff --git a/Sample.py b/Sample.py new file mode 100644 index 00000000..b502ef94 --- /dev/null +++ b/Sample.py @@ -0,0 +1,33 @@ +// Time Complexity : +// Space Complexity : +// Did this code successfully run on Leetcode : +// Any problem you faced while coding this : + + +// Your code here along with comments explaining your approach + +## Problem1 (https://leetcode.com/problems/sort-colors/) + +## Problem2 (https://leetcode.com/problems/3sum/) + +## Problem3 (https://leetcode.com/problems/container-with-most-water/) +## Time Complexity : O(n) +## Space Complexity : O(1) +## Did this code successfully run on Leetcode : Yes + +class Solution: + def maxArea(self, height: List[int]) -> int: + #brute force = nested for loop + + maxarea = 0 + i,j = 0,len(height)-1 + + while i < j: + area = min(height[i],height[j]) * abs(j-i) + maxarea = max(area,maxarea) + if height[i] <= height[j]: + i += 1 + elif height[j] < height[i]: + j -= 1 + + return maxarea \ No newline at end of file From 2ac46ba18d2fcf8926481e6f80c052d2c2bd4926 Mon Sep 17 00:00:00 2001 From: ankitakulkarnigit Date: Sun, 22 Mar 2026 00:31:34 -0700 Subject: [PATCH 2/3] container most water --- Sample.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Sample.py b/Sample.py index b502ef94..ba83f29d 100644 --- a/Sample.py +++ b/Sample.py @@ -9,6 +9,36 @@ ## Problem1 (https://leetcode.com/problems/sort-colors/) ## Problem2 (https://leetcode.com/problems/3sum/) +## Time Complexity : O(nlogn) +## Space Complexity : O(1) +# Hold one pivot pivot and then run 2sum + +class Solution: + def threeSum(self, nums: list[int]) -> list[list[int]]: + def twoSum(nums,pivot,res): + hashset = set() + i = pivot + 1 + while i < len(nums): + # a+b+c=0 --> c = -a-b -> a is the pivot, b is the current number and we are finding complement + comp = -nums[pivot] - nums[i] + if comp in hashset: + res.append([nums[pivot],nums[i],comp]) + while i + 1 < len(nums) and nums[i] == nums[i+1]: + i += 1 + hashset.add(nums[i]) + i += 1 + + res = [] + nums.sort() + prev = float(inf) + + for pivot in range(0,len(nums)): + if nums[pivot] > 0: + break + if pivot == 0 or nums[pivot-1] != nums[pivot]: + twoSum(nums,pivot,res) + return res + ## Problem3 (https://leetcode.com/problems/container-with-most-water/) ## Time Complexity : O(n) From e06a362459186a61789a2c69b8818f8b7b21ed6a Mon Sep 17 00:00:00 2001 From: ankitakulkarnigit Date: Sun, 22 Mar 2026 14:25:17 -0700 Subject: [PATCH 3/3] two pointers 1 --- Sample.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Sample.py b/Sample.py index ba83f29d..a4367ed9 100644 --- a/Sample.py +++ b/Sample.py @@ -7,6 +7,31 @@ // Your code here along with comments explaining your approach ## Problem1 (https://leetcode.com/problems/sort-colors/) +## Time Complexity : O(n) +## Space Complexity : O(1) +# bucket sort since only 3 integers to sort + +class Solution: + def sortColors(self, nums: List[int]) -> None: + """ + Do not return anything, modify nums in-place instead. + """ + hashmap = {} + for i in nums: + if i not in hashmap: + hashmap[i] = 0 + hashmap[i] += 1 + + for n in range(len(nums)): + if 0 in hashmap and hashmap[0] > 0: + nums[n] = 0 + hashmap[0] -= 1 + elif 1 in hashmap and hashmap[1] > 0: + nums[n] = 1 + hashmap[1] -= 1 + elif 2 in hashmap and hashmap[2] > 0: + nums[n] = 2 + hashmap[2] -= 1 ## Problem2 (https://leetcode.com/problems/3sum/) ## Time Complexity : O(nlogn)