From 193ea407d31446ec8dcd257a89647dc5cf3ef672 Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Sat, 10 Jan 2026 16:33:45 -0600 Subject: [PATCH 1/3] Completed TwoPointer1 --- Solutions.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Solutions.py diff --git a/Solutions.py b/Solutions.py new file mode 100644 index 00000000..5cdfe34b --- /dev/null +++ b/Solutions.py @@ -0,0 +1,105 @@ +Problem1 (https://leetcode.com/problems/sort-colors/) +Time Complexity : +Space Complexity : + + + + +class Solution(object): + def sortColors(self, nums): + """ + :type nums: List[int] + :rtype: None Do not return anything, modify nums in-place instead. + """ + low,high = 0,len(nums)-1 + mid = 0 + + while mid<=high: + if nums[mid] == 2: + nums[mid],nums[high] = nums[high],nums[mid] + high-=1 + elif nums[mid] == 0: + nums[mid],nums[low] = nums[low],nums[mid] + low+=1 + mid +=1 + else: + mid+=1 + + + + + +Problem2 (https://leetcode.com/problems/3sum/) +Time Complexity : O(n^2) +Space Complexity : O(1) + + +## sort the array so that we can manipulate left and right pointer +## for removing the duplicates, we can move i until it remains the same +## choose the l and r, check the sum, if sum ==0 add +## move left if sum <0 +## move right if sum > 0 + +class Solution(object): + def threeSum(self, nums): + """ + :type nums: List[int] + :rtype: List[List[int]] + """ + res = [] + nums.sort() + for i in range(len(nums)-1): + if i>0 and nums[i] == nums[i-1]: + continue + + l = i+1 + r = len(nums)-1 + while l0: + r-=1 + else: + res.append([nums[i],nums[l],nums[r]]) + l+=1 + r-=1 + while(l < r and nums[l] == nums[l - 1]): + l+=1 + while(l < r and nums[r] == nums[r + 1]): + r-=1 + + return res + + + +Problem3 (https://leetcode.com/problems/container-with-most-water/) +Time Complexity : O(n) +Space Complexity : O(1) + +class Solution(object): + def maxArea(self, height): + """ + :type height: List[int] + :rtype: int + """ + ## initialize left and right + ## check for water stored + ## replace with max + ## reduce or increase pointers + + l=0 + r=len(height)-1 + cur_area = max_area =0 + while(l height[r]: + r-=1 + else: + l+=1 + + return max_area \ No newline at end of file From bbc4a90eb1ba64f52af13362027d4741d10ddf83 Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Sat, 10 Jan 2026 16:50:56 -0600 Subject: [PATCH 2/3] Completed --- Solutions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Solutions.py b/Solutions.py index 5cdfe34b..f24d37f9 100644 --- a/Solutions.py +++ b/Solutions.py @@ -1,6 +1,6 @@ Problem1 (https://leetcode.com/problems/sort-colors/) -Time Complexity : -Space Complexity : +Time Complexity : O(n) +Space Complexity : O(1) From 4623fb711f57786da8bb8cc4367fe7deca03b7d7 Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Sat, 10 Jan 2026 16:51:48 -0600 Subject: [PATCH 3/3] Done --- Solutions.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Solutions.py b/Solutions.py index f24d37f9..e23721f1 100644 --- a/Solutions.py +++ b/Solutions.py @@ -3,7 +3,12 @@ Space Complexity : O(1) - +## we need to collect 0 at the start +## 1 in the mid +## 2 in the end +## so we can have three different pointers, check if the value is 2 replace +## check if the value is 0, replace from low , increment pointers +## else just increment mid class Solution(object): def sortColors(self, nums):