From aa2dc051ffaf69cee3408785dae3f39e5e7cd357 Mon Sep 17 00:00:00 2001 From: Bharath Vuppala Date: Thu, 16 Jan 2025 22:43:59 -0800 Subject: [PATCH 1/3] 3problems completed --- Merge Sorted Array.py | 27 +++++++++++++++++++++++++++ Remove Duplicates.py | 19 +++++++++++++++++++ Search In a 2d matrix.py | 22 ++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 Merge Sorted Array.py create mode 100644 Remove Duplicates.py create mode 100644 Search In a 2d matrix.py diff --git a/Merge Sorted Array.py b/Merge Sorted Array.py new file mode 100644 index 00000000..35e1f352 --- /dev/null +++ b/Merge Sorted Array.py @@ -0,0 +1,27 @@ +#Time complexity - 0(n+m) & space complexity - o(1) +class Solution: + def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: + if nums1 == None or len(nums1)==0: + return + p1=m-1 + p2= n-1 + p3=m+n-1 + + while p1>=0 and p2>=0: + if nums1[p1]=0: + nums1[p3]=nums2[p2] + p2=p2-1 + p3=p3-1 + + + + + + \ No newline at end of file diff --git a/Remove Duplicates.py b/Remove Duplicates.py new file mode 100644 index 00000000..0ebbe936 --- /dev/null +++ b/Remove Duplicates.py @@ -0,0 +1,19 @@ +class Solution: + def removeDuplicates(self, nums: List[int]) -> int: + + slow = 1 + count=1 + n= len(nums) + + for i in range (1, n): + if nums[i]==nums[i-1]: + count= count+1 + else: + count=1 + if count<=2: + nums[slow]=nums[i] + slow= slow+1 + return slow + + + \ No newline at end of file diff --git a/Search In a 2d matrix.py b/Search In a 2d matrix.py new file mode 100644 index 00000000..9e8a8fa5 --- /dev/null +++ b/Search In a 2d matrix.py @@ -0,0 +1,22 @@ +#Time complexity - 0(n+m) & space complexity - o(1) +class Solution: + def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: + if matrix == None or len(matrix)==0: + return False + m= len(matrix) + n=len(matrix[0]) + row =0 + col = n-1 + + while row=0: + if matrix[row][col]==target: + return True + elif matrix[row][col]>target: + col= col-1 + else: + row = row+1 + return False + + + + \ No newline at end of file From 85c017866a5dae198eca91dc09df5f60862eb1e3 Mon Sep 17 00:00:00 2001 From: BharathVuppala96 Date: Fri, 9 Jan 2026 12:34:34 -0800 Subject: [PATCH 2/3] 2problems completed --- Merge Sorted Array.py | 27 ------------------- Merge Sorted Array.py | 24 +++++++++++++++++ ... Remove Duplicates from sorted array II.py | 15 +++++------ Search In a 2d matrix.py | 22 --------------- search 2d matrix II.py | 14 ++++++++++ 5 files changed, 44 insertions(+), 58 deletions(-) delete mode 100644 Merge Sorted Array.py create mode 100644 Merge Sorted Array.py rename Remove Duplicates.py => Remove Duplicates from sorted array II.py (58%) delete mode 100644 Search In a 2d matrix.py create mode 100644 search 2d matrix II.py diff --git a/Merge Sorted Array.py b/Merge Sorted Array.py deleted file mode 100644 index 35e1f352..00000000 --- a/Merge Sorted Array.py +++ /dev/null @@ -1,27 +0,0 @@ -#Time complexity - 0(n+m) & space complexity - o(1) -class Solution: - def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: - if nums1 == None or len(nums1)==0: - return - p1=m-1 - p2= n-1 - p3=m+n-1 - - while p1>=0 and p2>=0: - if nums1[p1]=0: - nums1[p3]=nums2[p2] - p2=p2-1 - p3=p3-1 - - - - - - \ No newline at end of file diff --git a/Merge Sorted Array.py b/Merge Sorted Array.py new file mode 100644 index 00000000..24027577 --- /dev/null +++ b/Merge Sorted Array.py @@ -0,0 +1,24 @@ +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 + c=m+n-1 + + while p1>=0 and p2>=0: + if nums2[p2]>nums1[p1]: + nums1[c]=nums2[p2] + c=c-1 + p2=p2-1 + else: + nums1[c]=nums1[p1] + c=c-1 + p1=p1-1 + while p2>=0: + nums1[c]=nums2[p2] + c=c-1 + p2=p2-1 + + \ No newline at end of file diff --git a/Remove Duplicates.py b/Remove Duplicates from sorted array II.py similarity index 58% rename from Remove Duplicates.py rename to Remove Duplicates from sorted array II.py index 0ebbe936..d4ea32e2 100644 --- a/Remove Duplicates.py +++ b/Remove Duplicates from sorted array II.py @@ -1,19 +1,16 @@ class Solution: def removeDuplicates(self, nums: List[int]) -> int: - slow = 1 + slow=1 count=1 - n= len(nums) + n=len(nums) - for i in range (1, n): + for i in range(1,n): if nums[i]==nums[i-1]: - count= count+1 + count=count+1 else: count=1 if count<=2: nums[slow]=nums[i] - slow= slow+1 - return slow - - - \ No newline at end of file + slow=slow+1 + return slow \ No newline at end of file diff --git a/Search In a 2d matrix.py b/Search In a 2d matrix.py deleted file mode 100644 index 9e8a8fa5..00000000 --- a/Search In a 2d matrix.py +++ /dev/null @@ -1,22 +0,0 @@ -#Time complexity - 0(n+m) & space complexity - o(1) -class Solution: - def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: - if matrix == None or len(matrix)==0: - return False - m= len(matrix) - n=len(matrix[0]) - row =0 - col = n-1 - - while row=0: - if matrix[row][col]==target: - return True - elif matrix[row][col]>target: - col= col-1 - else: - row = row+1 - return False - - - - \ No newline at end of file diff --git a/search 2d matrix II.py b/search 2d matrix II.py new file mode 100644 index 00000000..d057189b --- /dev/null +++ b/search 2d matrix II.py @@ -0,0 +1,14 @@ +class Solution: + def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: + + m=0 + n=len(matrix[0])-1 + + while m=0: + if matrix[m][n]==target: + return True + elif target Date: Fri, 9 Jan 2026 12:40:09 -0800 Subject: [PATCH 3/3] 3problems completed --- ...sorted array II.py => RemoveDuplicates from sorted array II.py | 0 search 2d matrix II.py => search2d matrix II.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Remove Duplicates from sorted array II.py => RemoveDuplicates from sorted array II.py (100%) rename search 2d matrix II.py => search2d matrix II.py (100%) diff --git a/Remove Duplicates from sorted array II.py b/RemoveDuplicates from sorted array II.py similarity index 100% rename from Remove Duplicates from sorted array II.py rename to RemoveDuplicates from sorted array II.py diff --git a/search 2d matrix II.py b/search2d matrix II.py similarity index 100% rename from search 2d matrix II.py rename to search2d matrix II.py