From 21adc53a34ecb5b3b311b3f8911582a7086af564 Mon Sep 17 00:00:00 2001 From: "M.Hitesh" <54840773+hiteshmadapathi@users.noreply.github.com> Date: Fri, 7 Jan 2022 13:15:46 -0500 Subject: [PATCH 1/9] Create remove_duplicates.py --- remove_duplicates.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 remove_duplicates.py diff --git a/remove_duplicates.py b/remove_duplicates.py new file mode 100644 index 00000000..55e373a4 --- /dev/null +++ b/remove_duplicates.py @@ -0,0 +1,19 @@ +# Time Complexity - O(n) +# Space Complexity - O(1) + +class Solution: + + def removeDuplicates(self, nums: List[int]) -> int: + i = 1 + j = 1 + count = 1 + while j Date: Fri, 7 Jan 2022 13:29:45 -0500 Subject: [PATCH 2/9] Create merge_sorted_arrays.py --- merge_sorted_arrays.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 merge_sorted_arrays.py diff --git a/merge_sorted_arrays.py b/merge_sorted_arrays.py new file mode 100644 index 00000000..391a6188 --- /dev/null +++ b/merge_sorted_arrays.py @@ -0,0 +1,22 @@ +# Time Complexity - O(m+n) +# Space Complexity - O(1) + +class Solution: + + def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: + p1 = m-1 + p2 = n-1 + i = m+n-1 + while p1>=0 and p2>=0: + if nums1[p1]>nums2[p2]: + nums1[i] = nums1[p1] + p1 = p1-1 + else: + nums1[i] = nums2[p2] + p2 = p2-1 + i = i-1 + while p2>=0 and i>=0: + nums1[i]=nums2[p2] + p2 = p2-1 + i = i-1 + return nums1 From ffae24fe584a035319b9ad57a05d5822d40ef238 Mon Sep 17 00:00:00 2001 From: "M.Hitesh" <54840773+hiteshmadapathi@users.noreply.github.com> Date: Fri, 7 Jan 2022 13:32:58 -0500 Subject: [PATCH 3/9] Create search_2d_array.py --- search_2d_array.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 search_2d_array.py diff --git a/search_2d_array.py b/search_2d_array.py new file mode 100644 index 00000000..a5c281ed --- /dev/null +++ b/search_2d_array.py @@ -0,0 +1,16 @@ +# Time Complexity - O(n) +# Space Complexity - O(1) + +class Solution: + + def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: + i = 0 + j = len(matrix[0])-1 + while i=0: + if matrix[i][j]==target: + return True + elif matrix[i][j] Date: Thu, 30 Apr 2026 12:05:00 -0700 Subject: [PATCH 4/9] Delete merge_sorted_arrays.py --- merge_sorted_arrays.py | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 merge_sorted_arrays.py diff --git a/merge_sorted_arrays.py b/merge_sorted_arrays.py deleted file mode 100644 index 391a6188..00000000 --- a/merge_sorted_arrays.py +++ /dev/null @@ -1,22 +0,0 @@ -# Time Complexity - O(m+n) -# Space Complexity - O(1) - -class Solution: - - def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: - p1 = m-1 - p2 = n-1 - i = m+n-1 - while p1>=0 and p2>=0: - if nums1[p1]>nums2[p2]: - nums1[i] = nums1[p1] - p1 = p1-1 - else: - nums1[i] = nums2[p2] - p2 = p2-1 - i = i-1 - while p2>=0 and i>=0: - nums1[i]=nums2[p2] - p2 = p2-1 - i = i-1 - return nums1 From d403c7197d54c29cc17189e9bc7ae41e0400750f Mon Sep 17 00:00:00 2001 From: "M.Hitesh" <54840773+hiteshmadapathi@users.noreply.github.com> Date: Thu, 30 Apr 2026 12:05:08 -0700 Subject: [PATCH 5/9] Delete remove_duplicates.py --- remove_duplicates.py | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 remove_duplicates.py diff --git a/remove_duplicates.py b/remove_duplicates.py deleted file mode 100644 index 55e373a4..00000000 --- a/remove_duplicates.py +++ /dev/null @@ -1,19 +0,0 @@ -# Time Complexity - O(n) -# Space Complexity - O(1) - -class Solution: - - def removeDuplicates(self, nums: List[int]) -> int: - i = 1 - j = 1 - count = 1 - while j Date: Thu, 30 Apr 2026 12:05:16 -0700 Subject: [PATCH 6/9] Delete search_2d_array.py --- search_2d_array.py | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 search_2d_array.py diff --git a/search_2d_array.py b/search_2d_array.py deleted file mode 100644 index a5c281ed..00000000 --- a/search_2d_array.py +++ /dev/null @@ -1,16 +0,0 @@ -# Time Complexity - O(n) -# Space Complexity - O(1) - -class Solution: - - def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: - i = 0 - j = len(matrix[0])-1 - while i=0: - if matrix[i][j]==target: - return True - elif matrix[i][j] Date: Mon, 25 May 2026 06:56:40 -0700 Subject: [PATCH 7/9] Add removeDuplicates method to Solution class Implement a solution to remove duplicates from a sorted array, allowing at most two occurrences of each element. --- Problem1.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Problem1.py diff --git a/Problem1.py b/Problem1.py new file mode 100644 index 00000000..165d0d8a --- /dev/null +++ b/Problem1.py @@ -0,0 +1,22 @@ +# Time Complexity --> O(n) where n is the size of array +# Space Complexity --> O(1) +# Approach --> Use slow and fast pointers where the fast pointer keeps check on number of duplicates. If the count is more than 2, we reset the count and irrespective of the conditions the fast pointer moves. +class Solution: + def removeDuplicates(self, nums: List[int]) -> int: + if len(nums)<=1: + return len(nums) + slow = 1 + fast = 1 + count = 1 + while fast Date: Mon, 25 May 2026 07:08:54 -0700 Subject: [PATCH 8/9] Add merge function to merge two sorted arrays Implemented merge function to combine two sorted arrays in-place. --- Problem2.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Problem2.py diff --git a/Problem2.py b/Problem2.py new file mode 100644 index 00000000..465079ae --- /dev/null +++ b/Problem2.py @@ -0,0 +1,21 @@ +# Time Complexity --> O(m+n) where m and n are the number of elements from both arrays +# Space Complexity --> O(1) +class Solution: + def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: + """ + Do not return anything, modify nums1 in-place instead. + """ + p1 = m-1 + p2 = n-1 + d = m+n-1 + while p1>=0 and p2>=0: + if nums1[p1]>=nums2[p2]: + nums1[d] = nums1[p1] + p1 = p1-1 + else: + nums1[d] = nums2[p2] + p2 = p2-1 + d = d-1 + while p2>=0: + nums1[p2] = nums2[p2] + p2 = p2-1 From a05f19c164587105a8eb488c4ce492a96fe5ccfc Mon Sep 17 00:00:00 2001 From: "M.Hitesh" <54840773+hiteshmadapathi@users.noreply.github.com> Date: Mon, 25 May 2026 07:12:39 -0700 Subject: [PATCH 9/9] Create Problem3.py --- Problem3.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Problem3.py diff --git a/Problem3.py b/Problem3.py new file mode 100644 index 00000000..49dbee2e --- /dev/null +++ b/Problem3.py @@ -0,0 +1,15 @@ +# Time Complexity --> O(m+n) where m, n are the dimensions of matrix +# Space Complexity --> O(1) +class Solution: + def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: + r = len(matrix)-1 + c = 0 + + while r>=0 and c