From 6e9885c82d37fdbabfa29e1366711c9098209c34 Mon Sep 17 00:00:00 2001 From: Rajat Agarwal <36561091+rajatag03@users.noreply.github.com> Date: Sun, 3 Mar 2024 01:05:15 +0530 Subject: [PATCH 01/13] Create 724. Find Pivot Index --- 724. Find Pivot Index | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 724. Find Pivot Index diff --git a/724. Find Pivot Index b/724. Find Pivot Index new file mode 100644 index 0000000..c0bd1e9 --- /dev/null +++ b/724. Find Pivot Index @@ -0,0 +1,17 @@ +class Solution { + public int pivotIndex(int[] nums) { + int total=0; + for(int num:nums){ + total+=num; + } + + int leftSum=0; + for(int i=0;i Date: Sun, 3 Mar 2024 01:06:34 +0530 Subject: [PATCH 02/13] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index de043eb..c0356fe 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Number | Name of Problem | Leetcode Link | Video Link | Code 337 | House Robber III | https://leetcode.com/problems/house-robber-iii/ | https://youtu.be/FRP5l83XoZo | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/337.%20House%20Robber%20III 403 | Frog jump | https://leetcode.com/problems/frog-jump/ | https://youtu.be/3FYCPlIx3YA | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/403.%20Frog%20Jump 530 | Minimum Absolute Difference in BST | https://leetcode.com/problems/minimum-absolute-difference-in-bst/description/ | https://youtu.be/uDykjVZ5s4o | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/530.%20Minimum%20Absolute%20Difference%20in%20BST +724 | Find Pivot Index | https://leetcode.com/problems/find-pivot-index/description/ | https://youtu.be/HSg9QONpcPw | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/724.%20Find%20Pivot%20Index 862 | Shortest Subarray with Sum at Least K | https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/description/ | https://youtu.be/eWbH_j6Lgnk | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/862.%20Shortest%20Subarray%20with%20Sum%20at%20Least%20K 1071 | Greatest Common Divisor of Strings | https://leetcode.com/problems/greatest-common-divisor-of-strings/description/ | https://youtu.be/41iKYE0n0PQ | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/1071.%20Greatest%20Common%20Divisor%20of%20Strings 1129 | Shortest Path with Alternating Colors | https://leetcode.com/problems/shortest-path-with-alternating-colors/description/ | https://youtu.be/8FcdSwqR3Js | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/1129.%20Shortest%20Path%20with%20Alternating%20Colors From e99eae656a8d240bea7bdcee6da332bb299c8cb4 Mon Sep 17 00:00:00 2001 From: Rajat Agarwal <36561091+rajatag03@users.noreply.github.com> Date: Sun, 10 Mar 2024 21:27:40 +0530 Subject: [PATCH 03/13] Create 1751. Maximum Number of Events That Can Be Attended II --- ...m Number of Events That Can Be Attended II | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 1751. Maximum Number of Events That Can Be Attended II diff --git a/1751. Maximum Number of Events That Can Be Attended II b/1751. Maximum Number of Events That Can Be Attended II new file mode 100644 index 0000000..d099c85 --- /dev/null +++ b/1751. Maximum Number of Events That Can Be Attended II @@ -0,0 +1,51 @@ +class Solution { + int[][] dp=null; + public int maxValue(int[][] events, int k) { + int n = events.length; + dp = new int[n][k+1]; + for(int[] d:dp){ + Arrays.fill(d,-1); + } + if(k == 1) { + for(int[] event : events) { + max = Math.max(event[2], max); + } + return max; + } + + Arrays.sort(events,(a,b) -> a[0]==b[0]?a[1]-b[1]:a[0]-b[0]); + + return helper(events,0,k,n); //o(N*K) * O(logN) + } + + int helper(int[][] events,int pos,int k,int n){ + if(pos>=n || k==0){ + return 0; + } + + if(dp[pos][k]>-1){ + return dp[pos][k]; + } + + int nextPos = nextEvent(events,pos,n); // O(logN) + int select = events[pos][2] + helper(events,nextPos,k-1,n); + int reject = helper(events,pos+1,k,n); + dp[pos][k]= Math.max(select,reject); + return dp[pos][k]; + } + + int nextEvent(int[][] events,int pos, int n){ + int endDay = events[pos][1]; + pos++; + while(posendDay){ + n =mid; + } + else{ + pos = mid+1; + } + } + return n; + } +} From 0c841955de31d5f11bc3eb9d6fb9cac75450ac99 Mon Sep 17 00:00:00 2001 From: Rajat Agarwal <36561091+rajatag03@users.noreply.github.com> Date: Sun, 10 Mar 2024 21:29:18 +0530 Subject: [PATCH 04/13] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c0356fe..10bfc3e 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Number | Name of Problem | Leetcode Link | Video Link | Code 1510 | Stone Game IV | https://leetcode.com/problems/stone-game-iv/ | https://youtu.be/Gcg_a3r8FA0 | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/1510.%20Stone%20Game%20IV 1523 | Count Odd Numbers in an Interval Range | https://leetcode.com/problems/count-odd-numbers-in-an-interval-range/description/ | https://youtu.be/HxI78QECe0c | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/1523.%20Count%20Odd%20Numbers%20in%20an%20Interval%20Range 1696 | Jump Game VI | https://leetcode.com/problems/jump-game-vi/ | https://youtu.be/LiEcBMK5PQs | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/1696.%20Jump%20Game%20VI +1751 | Maximum Number of Events That Can Be Attended II | https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended-ii/description/ | https://youtu.be/C3r4OTOmfaI | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/1751.%20Maximum%20Number%20of%20Events%20That%20Can%20Be%20Attended%20II 1834 | Single-Threaded CPU | https://leetcode.com/problems/single-threaded-cpu/ | https://youtu.be/6104EJTG_T4 | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/1834.%20Single-Threaded%20CPU 1871 | Jump Game VII | https://leetcode.com/problems/jump-game-vii/ | https://youtu.be/bZxWLuiqHes | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/1871.%20Jump%20Game%20VII 2328 | Number of Increasing Paths in a Grid | https://leetcode.com/problems/number-of-increasing-paths-in-a-grid/description/ | https://youtu.be/kPAv1t2uBjg | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/2328.%20Number%20of%20Increasing%20Paths%20in%20a%20Grid From 6534d68862443b5d954fd01157d8cc12a23abdfb Mon Sep 17 00:00:00 2001 From: khushi3004 <46336275+khushi3004@users.noreply.github.com> Date: Fri, 29 Mar 2024 00:57:34 +0530 Subject: [PATCH 05/13] Create 2598. Length Of Longest Subarray with at most K Frequency --- ... Longest Subarray with at most K Frequency | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 2598. Length Of Longest Subarray with at most K Frequency diff --git a/2598. Length Of Longest Subarray with at most K Frequency b/2598. Length Of Longest Subarray with at most K Frequency new file mode 100644 index 0000000..4252307 --- /dev/null +++ b/2598. Length Of Longest Subarray with at most K Frequency @@ -0,0 +1,32 @@ +//Time Complexity - O(N) +//Space Complexity : O(N) + +class Solution { + public int maxSubarrayLength(int[] nums, int k) { + int start = 0, end = 0, result = 1; + Map freq = new HashMap<>(); + + while(end < nums.length) { + int currentFreq = freq.getOrDefault(nums[end], 0); + + if(currentFreq < k) { + freq.put(nums[end], currentFreq+1); + } + else { + while(nums[start] != nums[end]) { + freq.put(nums[start], freq.get(nums[start])-1); + start++; + } + start++; + } + + int newWindowLength = end-start+1; + result = Math.max(result, newWindowLength); + + end++; + + } + + return result; + } +} From 6f92cf3f3f68ce92ed4f29dcd66dddc5bc4f8d24 Mon Sep 17 00:00:00 2001 From: khushi3004 <46336275+khushi3004@users.noreply.github.com> Date: Fri, 29 Mar 2024 00:58:37 +0530 Subject: [PATCH 06/13] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 10bfc3e..8b4fc08 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Number | Name of Problem | Leetcode Link | Video Link | Code 2328 | Number of Increasing Paths in a Grid | https://leetcode.com/problems/number-of-increasing-paths-in-a-grid/description/ | https://youtu.be/kPAv1t2uBjg | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/2328.%20Number%20of%20Increasing%20Paths%20in%20a%20Grid 2375 | Construct Smallest Number From DI String | https://leetcode.com/problems/construct-smallest-number-from-di-string/ | https://youtu.be/GEqSg0Otq4Y | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/2375.%20Construct%20Smallest%20Number%20From%20DI%20String 2531 | Make Number of Distinct Characters Equal | https://leetcode.com/problems/make-number-of-distinct-characters-equal/description/ | https://youtu.be/GwWmlpIEIwc | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/2531.%20Make%20Number%20of%20Distinct%20Characters%20Equal +2598 | Length Of Longest Subarray with at most K Frequency | https://leetcode.com/problems/length-of-longest-subarray-with-at-most-k-frequency/ | https://youtu.be/GwWmlpIEIwc | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/2598.%20Length%20Of%20Longest%20Subarray%20with%20at%20most%20K%20Frequency 2657 | Find the Prefix Common Array of Two Arrays | https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays/description/ | https://youtu.be/m6s9dBCBocQ | https://github.com/Algorithms-Made-Easy/Leetcode-Challenge/blob/main/2657.%20Find%20the%20Prefix%20Common%20Array%20of%20Two%20Arrays # Leetcode-Challenge From 473e9b7c2d03bd3dcae2f96c0602e858cbaa7419 Mon Sep 17 00:00:00 2001 From: khushi3004 <46336275+khushi3004@users.noreply.github.com> Date: Fri, 29 Mar 2024 11:10:06 +0530 Subject: [PATCH 07/13] Rename 2598. Length Of Longest Subarray with at most K Frequency to 2958. Length Of Longest Subarray with at most K Frequency --- ...y => 2958. Length Of Longest Subarray with at most K Frequency | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 2598. Length Of Longest Subarray with at most K Frequency => 2958. Length Of Longest Subarray with at most K Frequency (100%) diff --git a/2598. Length Of Longest Subarray with at most K Frequency b/2958. Length Of Longest Subarray with at most K Frequency similarity index 100% rename from 2598. Length Of Longest Subarray with at most K Frequency rename to 2958. Length Of Longest Subarray with at most K Frequency From 21bbebfa47597dee0a93d371a1a8478887794c22 Mon Sep 17 00:00:00 2001 From: Rajat Agarwal <36561091+rajatag03@users.noreply.github.com> Date: Sat, 28 Dec 2024 23:37:09 +0530 Subject: [PATCH 08/13] Create Code Testcase Test Result Test Result 1014. Best Sightseeing Pair --- ...est Result Test Result 1014. Best Sightseeing Pair | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Code Testcase Test Result Test Result 1014. Best Sightseeing Pair diff --git a/Code Testcase Test Result Test Result 1014. Best Sightseeing Pair b/Code Testcase Test Result Test Result 1014. Best Sightseeing Pair new file mode 100644 index 0000000..bc90bac --- /dev/null +++ b/Code Testcase Test Result Test Result 1014. Best Sightseeing Pair @@ -0,0 +1,11 @@ +class Solution { + public int maxScoreSightseeingPair(int[] values) { + int result =0; + int max = values[0]; + for(int i=1;i Date: Sat, 28 Dec 2024 23:38:52 +0530 Subject: [PATCH 09/13] Rename Code Testcase Test Result Test Result 1014. Best Sightseeing Pair to 1014. Best Sightseeing PairTest Result 1014. Best Sightseeing Pair --- .... Best Sightseeing PairTest Result 1014. Best Sightseeing Pair | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Code Testcase Test Result Test Result 1014. Best Sightseeing Pair => 1014. Best Sightseeing PairTest Result 1014. Best Sightseeing Pair (100%) diff --git a/Code Testcase Test Result Test Result 1014. Best Sightseeing Pair b/1014. Best Sightseeing PairTest Result 1014. Best Sightseeing Pair similarity index 100% rename from Code Testcase Test Result Test Result 1014. Best Sightseeing Pair rename to 1014. Best Sightseeing PairTest Result 1014. Best Sightseeing Pair From 8606116d20319a6d6b1f7e9dbbc4eb6d968428e9 Mon Sep 17 00:00:00 2001 From: Rajat Agarwal <36561091+rajatag03@users.noreply.github.com> Date: Sat, 28 Dec 2024 23:39:16 +0530 Subject: [PATCH 10/13] Rename 1014. Best Sightseeing PairTest Result 1014. Best Sightseeing Pair to 1014. Best Sightseeing PairTest Result --- ...est Sightseeing Pair => 1014. Best Sightseeing PairTest Result | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1014. Best Sightseeing PairTest Result 1014. Best Sightseeing Pair => 1014. Best Sightseeing PairTest Result (100%) diff --git a/1014. Best Sightseeing PairTest Result 1014. Best Sightseeing Pair b/1014. Best Sightseeing PairTest Result similarity index 100% rename from 1014. Best Sightseeing PairTest Result 1014. Best Sightseeing Pair rename to 1014. Best Sightseeing PairTest Result From 56766e20acbafebc5caaa593b0a6fbb4254c70c6 Mon Sep 17 00:00:00 2001 From: Rajat Agarwal <36561091+rajatag03@users.noreply.github.com> Date: Sat, 28 Dec 2024 23:39:28 +0530 Subject: [PATCH 11/13] Rename 1014. Best Sightseeing PairTest Result to 1014. Best Sightseeing Pair --- ...est Sightseeing PairTest Result => 1014. Best Sightseeing Pair | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 1014. Best Sightseeing PairTest Result => 1014. Best Sightseeing Pair (100%) diff --git a/1014. Best Sightseeing PairTest Result b/1014. Best Sightseeing Pair similarity index 100% rename from 1014. Best Sightseeing PairTest Result rename to 1014. Best Sightseeing Pair From c478889c894484aaf3bc6edd2a137ece656caaa8 Mon Sep 17 00:00:00 2001 From: Rajat Agarwal <36561091+rajatag03@users.noreply.github.com> Date: Tue, 14 Jan 2025 22:47:06 +0530 Subject: [PATCH 12/13] Create 3223. Minimum Length of String After Operations --- 3223. Minimum Length of String After Operations | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 3223. Minimum Length of String After Operations diff --git a/3223. Minimum Length of String After Operations b/3223. Minimum Length of String After Operations new file mode 100644 index 0000000..506570d --- /dev/null +++ b/3223. Minimum Length of String After Operations @@ -0,0 +1,14 @@ +class Solution { + public int minimumLength(String s) { + char[] ch = s.toCharArray(); + int[] count = new int[26]; + for(char c:ch){ + count[c-'a']++; + } + int result = 0; + for(int ct: count){ + if(ct>0) result+=(ct%2==0?2:1); + } + return result; + } +} From 9c2fb05e0d692a3584b49bb8efe50fe42a6060a7 Mon Sep 17 00:00:00 2001 From: Rajat Agarwal <36561091+rajatag03@users.noreply.github.com> Date: Tue, 28 Jan 2025 10:20:17 +0530 Subject: [PATCH 13/13] Create 2116. Check if a Parentheses String Can Be Valid --- ...Check if a Parentheses String Can Be Valid | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 2116. Check if a Parentheses String Can Be Valid diff --git a/2116. Check if a Parentheses String Can Be Valid b/2116. Check if a Parentheses String Can Be Valid new file mode 100644 index 0000000..4875d5f --- /dev/null +++ b/2116. Check if a Parentheses String Can Be Valid @@ -0,0 +1,36 @@ +class Solution { + public boolean canBeValid(String s, String locked) { + if(s.length()%2!=0) return false; + Stack unlocked = new Stack<>(); + Stack open = new Stack<>(); + char[] stArray = s.toCharArray(); + char[] lArray = locked.toCharArray(); + + for(int i=0;i0){ + open.pop(); + } + else if(unlocked.size()>0){ + unlocked.pop(); + } + else{ + return false; + } + } + } + + while(open.size()>0 && unlocked.size()>0 && open.peek()