From c5372fb70462374ec3291f4f48f2e2fa87587b43 Mon Sep 17 00:00:00 2001 From: agk-s30 Date: Wed, 12 Aug 2026 19:57:02 -0700 Subject: [PATCH 1/3] Add maxArea function for water container problem Implement maxArea function to calculate the maximum water container area using two-pointer technique. --- Problem_3.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Problem_3.py diff --git a/Problem_3.py b/Problem_3.py new file mode 100644 index 00000000..88df8908 --- /dev/null +++ b/Problem_3.py @@ -0,0 +1,21 @@ +# https://leetcode.com/problems/container-with-most-water/ + +# TC: O(n) +# SC: O(1) +# Explanation: Maintain two pointers starting at index 0 and n - 1; keep moving the pointers based on highest point; +# at each pass find the max area; return the final max area + +class Solution: + def maxArea(self, height: List[int]) -> int: + n = len(height) + l, r = 0, n - 1 + m_height = 0 + + while l < r: + m_height = max(m_height, min(height[l], height[r]) * (r - l)) + if height[l] < height[r]: + l += 1 + else: + r -= 1 + + return m_height From 9e4b33cbf51941be6960ea51cfdde4353bab2df7 Mon Sep 17 00:00:00 2001 From: agk-s30 Date: Sun, 16 Aug 2026 21:58:57 -0700 Subject: [PATCH 2/3] Create Problem_1.py --- Problem_1.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Problem_1.py diff --git a/Problem_1.py b/Problem_1.py new file mode 100644 index 00000000..0602f272 --- /dev/null +++ b/Problem_1.py @@ -0,0 +1,28 @@ +# https://leetcode.com/problems/sort-colors/ + +# Time complexity: O(n) +# Space complexity: O(1) +# Explanation: Use 3 pointers, and move every 0 to the left, every 2 to the right, and keep the 1s in the middle; +# while swapping make sure left side swaps increment both p0 and curr pointer because those values have been checked +# but right side swaps increment only p2 because those values have not been checked + +class Solution: + def sortColors(self, nums: List[int]) -> None: + """ + Do not return anything, modify nums in-place instead. + """ + n = len(nums) + p0, p2 = 0, n - 1 + curr = 0 + while curr <= p2: + if nums[curr] == 0: + nums[p0], nums[curr] = nums[curr], nums[p0] + p0 += 1 + curr += 1 + elif nums[curr] == 2: + nums[p2], nums[curr] = nums[curr], nums[p2] + p2 -= 1 + else: + curr += 1 + + From 808a82306c0b5ec7119b2bcaa856858673197835 Mon Sep 17 00:00:00 2001 From: agk-s30 Date: Sun, 16 Aug 2026 23:33:50 -0700 Subject: [PATCH 3/3] Add solution for 3Sum problem in Problem_2.py Implement 3Sum problem solution with twoSum helper function. --- Problem_2.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Problem_2.py diff --git a/Problem_2.py b/Problem_2.py new file mode 100644 index 00000000..99102e43 --- /dev/null +++ b/Problem_2.py @@ -0,0 +1,33 @@ +# https://leetcode.com/problems/3sum/ + +# Time complexity: O(n^2) +# Space complexity: O(n) +# Explanation: Take each number that is less than 0, and try to find subarrays whhere sum is 0; +# to find subarray assume the search space is for current index i to end of array + +class Solution: + def twoSum(self, nums: list[int], i: int, res: list[list[int]]): + low, high = i + 1, len(nums) - 1 + while low < high: + sum = nums[i] + nums[low] + nums[high] + if sum < 0: + low += 1 + elif sum > 0: + high -= 1 + else: + res.append([nums[i], nums[low], nums[high]]) + low += 1 + high -= 1 + while low < high and nums[low - 1] == nums[low]: + low += 1 + + + def threeSum(self, nums: list[int]) -> list[list[int]]: + res = [] + nums.sort() + for i in range(len(nums)): + if nums[i] > 0: + break + if i == 0 or nums[i - 1] != nums[i]: + self.twoSum(nums, i, res) + return res