From c9d5e90df9f4ae07c022a8552fb5c3266fd96226 Mon Sep 17 00:00:00 2001 From: Amaan-29 Date: Sat, 10 Jan 2026 18:38:28 -0500 Subject: [PATCH 1/2] Merged sorted arrays and Remove duplicates HW --- .idea/.gitignore | 3 ++ .idea/Two-Pointers-2.iml | 11 +++++++ .idea/codeStyles/Project.xml | 7 ++++ .idea/codeStyles/codeStyleConfig.xml | 5 +++ .idea/misc.xml | 6 ++++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 6 ++++ MergeSortedArrays.java | 30 ++++++++++++++++++ RemoveDuplicates.java | 19 +++++++++++ .../Two-Pointers-2/.idea/.gitignore | 3 ++ .../Two-Pointers-2/.idea/Two-Pointers-2.iml | 11 +++++++ .../.idea/codeStyles/Project.xml | 7 ++++ .../.idea/codeStyles/codeStyleConfig.xml | 5 +++ out/production/Two-Pointers-2/.idea/misc.xml | 6 ++++ .../Two-Pointers-2/.idea/modules.xml | 8 +++++ out/production/Two-Pointers-2/.idea/vcs.xml | 6 ++++ .../Two-Pointers-2/MergeSortedArrays.class | Bin 0 -> 1111 bytes out/production/Two-Pointers-2/README.md | 10 ++++++ .../Two-Pointers-2/RemoveDuplicates.class | Bin 0 -> 835 bytes 19 files changed, 151 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/Two-Pointers-2.iml create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 MergeSortedArrays.java create mode 100644 RemoveDuplicates.java create mode 100644 out/production/Two-Pointers-2/.idea/.gitignore create mode 100644 out/production/Two-Pointers-2/.idea/Two-Pointers-2.iml create mode 100644 out/production/Two-Pointers-2/.idea/codeStyles/Project.xml create mode 100644 out/production/Two-Pointers-2/.idea/codeStyles/codeStyleConfig.xml create mode 100644 out/production/Two-Pointers-2/.idea/misc.xml create mode 100644 out/production/Two-Pointers-2/.idea/modules.xml create mode 100644 out/production/Two-Pointers-2/.idea/vcs.xml create mode 100644 out/production/Two-Pointers-2/MergeSortedArrays.class create mode 100644 out/production/Two-Pointers-2/README.md create mode 100644 out/production/Two-Pointers-2/RemoveDuplicates.class diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Two-Pointers-2.iml b/.idea/Two-Pointers-2.iml new file mode 100644 index 00000000..b107a2dd --- /dev/null +++ b/.idea/Two-Pointers-2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..919ce1f1 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..a55e7a17 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..f5bd2dfe --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..827d064a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MergeSortedArrays.java b/MergeSortedArrays.java new file mode 100644 index 00000000..a0279a1e --- /dev/null +++ b/MergeSortedArrays.java @@ -0,0 +1,30 @@ +import java.util.Arrays; +public class MergeSortedArrays { + public void merge(int[] nums1, int m, int[] nums2, int n){ + int i = m - 1; + int j = n - 1; + int k = m + n - 1; + while(i >= 0 && j >= 0){ + if(nums1[i] >= nums2[j]){ + nums1[k] = nums1[i]; + k--; + i--; + }else{ + nums1[k] = nums2[j]; + k--; + j--; + } + } + } + public static void main(String[] args){ + MergeSortedArrays solution = new MergeSortedArrays(); + + int [] nums1 = {1,2,3,0,0,0}; int m = 3; + int [] nums2 = {2,5,6}; int n = 3; + solution.merge(nums1, m, nums2, n); + System.out.println(Arrays.toString(nums1)); + } +} + +//Time complexity : O(m+n) +//Space complexity : O(1) \ No newline at end of file diff --git a/RemoveDuplicates.java b/RemoveDuplicates.java new file mode 100644 index 00000000..656cb3d1 --- /dev/null +++ b/RemoveDuplicates.java @@ -0,0 +1,19 @@ +public class RemoveDuplicates { + public static int removeDuplicates(int[] nums) { + int i = 0; + for(int n: nums){ + if(i<2 || n!=nums[i-2]){ + nums[i++]=n; + } + } + return i; + } + public static void main(String[] args){ + int[] nums={1,1,1,2,2,3,3,4}; + System.out.println(removeDuplicates(nums)); + } +} + + +//Time complexity : O(n) +//Space complexity : O(1) \ No newline at end of file diff --git a/out/production/Two-Pointers-2/.idea/.gitignore b/out/production/Two-Pointers-2/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/out/production/Two-Pointers-2/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/out/production/Two-Pointers-2/.idea/Two-Pointers-2.iml b/out/production/Two-Pointers-2/.idea/Two-Pointers-2.iml new file mode 100644 index 00000000..b107a2dd --- /dev/null +++ b/out/production/Two-Pointers-2/.idea/Two-Pointers-2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Two-Pointers-2/.idea/codeStyles/Project.xml b/out/production/Two-Pointers-2/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..919ce1f1 --- /dev/null +++ b/out/production/Two-Pointers-2/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Two-Pointers-2/.idea/codeStyles/codeStyleConfig.xml b/out/production/Two-Pointers-2/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..a55e7a17 --- /dev/null +++ b/out/production/Two-Pointers-2/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/out/production/Two-Pointers-2/.idea/misc.xml b/out/production/Two-Pointers-2/.idea/misc.xml new file mode 100644 index 00000000..f5bd2dfe --- /dev/null +++ b/out/production/Two-Pointers-2/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Two-Pointers-2/.idea/modules.xml b/out/production/Two-Pointers-2/.idea/modules.xml new file mode 100644 index 00000000..827d064a --- /dev/null +++ b/out/production/Two-Pointers-2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/Two-Pointers-2/.idea/vcs.xml b/out/production/Two-Pointers-2/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/out/production/Two-Pointers-2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Two-Pointers-2/MergeSortedArrays.class b/out/production/Two-Pointers-2/MergeSortedArrays.class new file mode 100644 index 0000000000000000000000000000000000000000..8704db39860c3a76af63512812b7570c0dc03803 GIT binary patch literal 1111 zcmZ`&T~8B16g|`ZYDe&5hw=K1T^RZ$sPNx zov+!AYTnw~aVmj;zUVgGU`aqpXEqE(1-jQ9zv`4cKXA5}ec#@1#$iB_Q%3>`bP8y7 znIaHNZx#xCGaE5xPU1fqe*T(?mbND(yCE)yzg`&r{Eh7F7)a1GZ5dN08dF!m&BtwAE` zizPA}0_qcQo65S1Zo_%rs&6^|D|@R(PfyXS*tHGYcjf-fsRnP{Cc%mqdbYqWHCpxN zj6h_wARyQR!8LTw(k2Jta_n&I3UrnNyRy4x@10k!+b&Zm_CGvrzbcV03A0;Gug3Oy zED$ewEx+QdxKcyv0?nLk6K?R^MtEZY1*8a_^C)+Du7ayJaSZW+Mue#d!_vMGw1!iz7& zc#;hApiHLI-YR#{i9vcVBmtTlZpj54A|8BOZe zLsg&GvXdi&s;M0z{t;IuKcVjkLw~=L!soQHUZ3FmPDc` kusLI-H%=i^e1xYaLh%Y)HV}$eS;eGRN*1`sa}mt_0ee!-8UO$Q literal 0 HcmV?d00001 diff --git a/out/production/Two-Pointers-2/README.md b/out/production/Two-Pointers-2/README.md new file mode 100644 index 00000000..e1a6f9d6 --- /dev/null +++ b/out/production/Two-Pointers-2/README.md @@ -0,0 +1,10 @@ +# Two-Pointers-2 + +## Problem1 (https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/) + + +## Problem2 (https://leetcode.com/problems/merge-sorted-array/) + + +## Problem3 (https://leetcode.com/problems/search-a-2d-matrix-ii/) + diff --git a/out/production/Two-Pointers-2/RemoveDuplicates.class b/out/production/Two-Pointers-2/RemoveDuplicates.class new file mode 100644 index 0000000000000000000000000000000000000000..ad2180e8a9d8aa28ab1003fac0d3897ae2955337 GIT binary patch literal 835 zcmZuvO>YuW6g_V~7?=(%f`eLG6+c>_6{5y&sNHBxNNC51At9^=I>D*TK&C?z_x&G6 zH^#(`F4P#)AK*{$ml$KL=Rp%=?c%=o?tSN;d*;0P_WR2bfcsc8p+GgDSgPPOZ^ZKzsV$%=(cuPPnmD?#KkuqRfn1l5Xy!B!~_5z|t6E@k+DUm;_J&yb^ zZpD%326YqjSTK;Wa1L2^Kkce(ZVyJgp1?xW551j9(DS0FZg0p+wmIs%!?qjwGCwJ5@iU(qvdz=F z>H>nKqCv)R5)h+wc^1Avx)rr5_6Tpp%Aw2 z9BSgt@%O?zHmcKMi&GMnqc!BI?I!bEJm2LoDc~w`dA{LgT;VOpu~Ou&5OIw)f$Pkc zpdG`6Zs3NH!4LR_Me!5H4|b) Date: Sun, 11 Jan 2026 23:49:47 -0500 Subject: [PATCH 2/2] Completed SearchMatrix HW --- SearchMatrix.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 SearchMatrix.java diff --git a/SearchMatrix.java b/SearchMatrix.java new file mode 100644 index 00000000..7afeea61 --- /dev/null +++ b/SearchMatrix.java @@ -0,0 +1,23 @@ +public class SearchMatrix { + public boolean searchMatrix(int[][] matrix, int target) { + int m = matrix.length; + int n = matrix[0].length; + int i = 0; + int j = n - 1; + while(i < m && j >= 0 ){ + if(matrix[i][j] == target) return true; + else if(matrix[i][j] > target){ + j--; + } else{ + i++; + } + } + return false; + } +} + +//TC :Time Complexity: +//O(m log n) + +//Space Complexity: +//O(1) \ No newline at end of file