From e3f477ddc8683c7766fa7e82920db903804f96a1 Mon Sep 17 00:00:00 2001 From: Yash Garg <72246420+yashgarg7302@users.noreply.github.com> Date: Mon, 13 Jan 2025 01:01:19 +0530 Subject: [PATCH 01/13] _916.cpp (#190) * Create _916 Solution for the leetcode daily question 916. Word Subsets * Rename _916 to _916.cpp --- cpp/_916.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 cpp/_916.cpp diff --git a/cpp/_916.cpp b/cpp/_916.cpp new file mode 100644 index 0000000000..7ac4a644a1 --- /dev/null +++ b/cpp/_916.cpp @@ -0,0 +1,34 @@ +class Solution { +public: + vector wordSubsets(vector& words1, vector& words2) { + int maxCharFreq[26] = {0}; + int tempCharFreq[26]; + for (const auto& word : words2) { + memset(tempCharFreq, 0, sizeof tempCharFreq); + for (char ch : word) { + tempCharFreq[ch - 'a']++; + } + for (int i = 0; i < 26; ++i) { + maxCharFreq[i] = max(maxCharFreq[i], tempCharFreq[i]); + } + } + vector universalWords; + for (const auto& word : words1) { + memset(tempCharFreq, 0, sizeof tempCharFreq); + for (char ch : word) { + tempCharFreq[ch - 'a']++; + } + bool isUniversal = true; + for (int i = 0; i < 26; ++i) { + if (maxCharFreq[i] > tempCharFreq[i]) { + isUniversal = false; + break; + } + } + if (isUniversal) { + universalWords.emplace_back(word); + } + } + return universalWords; + } +}; From 0d31b5ae998cfed18e477028d0b0b3fc28d3de9c Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 26 Jan 2025 15:56:31 -0800 Subject: [PATCH 02/13] [LEET-3386] add 3386 --- .../algorithms/4th_thousand/README.md | 1 + .../solutions/fourththousand/_3386.java | 32 +++++++++++ .../fishercoder/fourththousand/_3386Test.java | 53 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/fourththousand/_3386.java create mode 100644 src/test/java/com/fishercoder/fourththousand/_3386Test.java diff --git a/paginated_contents/algorithms/4th_thousand/README.md b/paginated_contents/algorithms/4th_thousand/README.md index 9b9752a45e..f1841d6bd3 100644 --- a/paginated_contents/algorithms/4th_thousand/README.md +++ b/paginated_contents/algorithms/4th_thousand/README.md @@ -2,6 +2,7 @@ |------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|---------------------------------------------------------------------- | 3396 | [Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java) | | Easy | | 3392 | [Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3392.java) | | Easy | +| 3386 | [Button with Longest Push Time](https://leetcode.com/problems/button-with-longest-push-time/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3386.java) | | Easy | | 3379 | [Transformed Array](https://leetcode.com/problems/transformed-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3379.java) | | Easy | | 3375 | [Minimum Operations to Make Array Values Equal to K](https://leetcode.com/problems/minimum-operations-to-make-array-values-equal-to-k/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3375.java) | | Easy | | 3370 | [Smallest Number With All Set Bits](https://leetcode.com/problems/smallest-number-with-all-set-bits/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3370.java) | | Easy | diff --git a/src/main/java/com/fishercoder/solutions/fourththousand/_3386.java b/src/main/java/com/fishercoder/solutions/fourththousand/_3386.java new file mode 100644 index 0000000000..530e18ea6a --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/fourththousand/_3386.java @@ -0,0 +1,32 @@ +package com.fishercoder.solutions.fourththousand; + +import java.util.HashMap; +import java.util.Map; + +public class _3386 { + public static class Solution1 { + public int buttonWithLongestTime(int[][] events) { + Map map = new HashMap<>(); + int ans = events[0][0]; + map.put(events[0][0], events[0][1]); + for (int i = 1; i < events.length; i++) { + int duration = events[i][1] - events[i - 1][1]; + if (map.getOrDefault(events[i][0], 0) < duration) { + map.put(events[i][0], duration); + } + } + int maxDuration = events[0][1]; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() > maxDuration) { + ans = entry.getKey(); + maxDuration = entry.getValue(); + } else if (entry.getValue() == maxDuration) { + if (entry.getKey() < ans) { + ans = entry.getKey(); + } + } + } + return ans; + } + } +} diff --git a/src/test/java/com/fishercoder/fourththousand/_3386Test.java b/src/test/java/com/fishercoder/fourththousand/_3386Test.java new file mode 100644 index 0000000000..703d54bb06 --- /dev/null +++ b/src/test/java/com/fishercoder/fourththousand/_3386Test.java @@ -0,0 +1,53 @@ +package com.fishercoder.fourththousand; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.fishercoder.common.utils.CommonUtils; +import com.fishercoder.solutions.fourththousand._3386; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class _3386Test { + private _3386.Solution1 solution1; + + @BeforeEach + public void setup() { + solution1 = new _3386.Solution1(); + } + + @Test + public void test1() { + assertEquals( + 1, + solution1.buttonWithLongestTime( + CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray( + "[1,2],[2,5],[3,9],[1,15]"))); + } + + @Test + public void test2() { + assertEquals( + 2, + solution1.buttonWithLongestTime( + CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray( + "[9,4],[19,5],[2,8],[3,11],[2,15]"))); + } + + @Test + public void test3() { + assertEquals( + 2, + solution1.buttonWithLongestTime( + CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray( + "[7,1],[19,3],[9,4],[12,5],[2,8],[15,10],[18,12],[7,14],[19,16]"))); + } + + @Test + public void test4() { + assertEquals( + 16, + solution1.buttonWithLongestTime( + CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray( + "[5,5],[16,17],[16,19]"))); + } +} From e5982a97b3720d4738cf7340540a741cffa06d3f Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Mon, 3 Mar 2025 13:42:07 -0800 Subject: [PATCH 03/13] [LEET-3471] add 3471 --- .../algorithms/4th_thousand/README.md | 1 + .../solutions/fourththousand/_3471.java | 31 +++++++++++++++++++ .../fishercoder/fourththousand/_3471Test.java | 26 ++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/fourththousand/_3471.java create mode 100644 src/test/java/com/fishercoder/fourththousand/_3471Test.java diff --git a/paginated_contents/algorithms/4th_thousand/README.md b/paginated_contents/algorithms/4th_thousand/README.md index f1841d6bd3..48ebbd7a0a 100644 --- a/paginated_contents/algorithms/4th_thousand/README.md +++ b/paginated_contents/algorithms/4th_thousand/README.md @@ -1,5 +1,6 @@ | # | Title | Solutions | Video | Difficulty | Tag |------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|---------------------------------------------------------------------- +| 3471 | [Find the Largest Almost Missing Integer](https://leetcode.com/problems/find-the-largest-almost-missing-integer/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3471.java) | | Easy | | 3396 | [Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java) | | Easy | | 3392 | [Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3392.java) | | Easy | | 3386 | [Button with Longest Push Time](https://leetcode.com/problems/button-with-longest-push-time/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3386.java) | | Easy | diff --git a/src/main/java/com/fishercoder/solutions/fourththousand/_3471.java b/src/main/java/com/fishercoder/solutions/fourththousand/_3471.java new file mode 100644 index 0000000000..9926ed7f16 --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/fourththousand/_3471.java @@ -0,0 +1,31 @@ +package com.fishercoder.solutions.fourththousand; + +import java.util.HashSet; +import java.util.Set; +import java.util.TreeMap; + +public class _3471 { + public static class Solution1 { + public int largestInteger(int[] nums, int k) { + TreeMap map = new TreeMap<>(); + for (int num : nums) { + map.put(num, 0); + } + for (int i = 0; i <= nums.length - k; i++) { + Set set = new HashSet<>(); + for (int j = i; j < i + k; j++) { + if (set.add(nums[j])) { + map.put(nums[j], map.getOrDefault(nums[j], 0) + 1); + } + } + } + int ans = -1; + for (int key : map.keySet()) { + if (map.get(key) == 1) { + ans = key; + } + } + return ans; + } + } +} diff --git a/src/test/java/com/fishercoder/fourththousand/_3471Test.java b/src/test/java/com/fishercoder/fourththousand/_3471Test.java new file mode 100644 index 0000000000..5b825f5f8d --- /dev/null +++ b/src/test/java/com/fishercoder/fourththousand/_3471Test.java @@ -0,0 +1,26 @@ +package com.fishercoder.fourththousand; + +import com.fishercoder.solutions.fourththousand._3471; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class _3471Test { + private _3471.Solution1 solution1; + + @BeforeEach + public void setup() { + solution1 = new _3471.Solution1(); + } + + @Test + public void test1() { + assertEquals(7, solution1.largestInteger(new int[]{3, 9, 2, 1, 7}, 3)); + } + + @Test + public void test2() { + assertEquals(0, solution1.largestInteger(new int[]{0, 0}, 2)); + } +} From efa91d4dc97a874d3d4e1f2039682f82d1d69462 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Mon, 3 Mar 2025 13:42:24 -0800 Subject: [PATCH 04/13] [LEET-3471] add 3471 test --- .../java/com/fishercoder/fourththousand/_3471Test.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/fishercoder/fourththousand/_3471Test.java b/src/test/java/com/fishercoder/fourththousand/_3471Test.java index 5b825f5f8d..f14977034d 100644 --- a/src/test/java/com/fishercoder/fourththousand/_3471Test.java +++ b/src/test/java/com/fishercoder/fourththousand/_3471Test.java @@ -1,11 +1,11 @@ package com.fishercoder.fourththousand; +import static org.junit.jupiter.api.Assertions.assertEquals; + import com.fishercoder.solutions.fourththousand._3471; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class _3471Test { private _3471.Solution1 solution1; @@ -16,11 +16,11 @@ public void setup() { @Test public void test1() { - assertEquals(7, solution1.largestInteger(new int[]{3, 9, 2, 1, 7}, 3)); + assertEquals(7, solution1.largestInteger(new int[] {3, 9, 2, 1, 7}, 3)); } @Test public void test2() { - assertEquals(0, solution1.largestInteger(new int[]{0, 0}, 2)); + assertEquals(0, solution1.largestInteger(new int[] {0, 0}, 2)); } } From 6adfdf0b506b12f6e12cd40cabbdbbdefe51aee7 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Mon, 31 Mar 2025 15:03:56 -0700 Subject: [PATCH 05/13] [LEET-3502] add 3502 --- .../algorithms/4th_thousand/README.md | 1 + .../solutions/fourththousand/_3502.java | 17 ++++++++++++++ .../fishercoder/fourththousand/_3502Test.java | 22 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/fourththousand/_3502.java create mode 100644 src/test/java/com/fishercoder/fourththousand/_3502Test.java diff --git a/paginated_contents/algorithms/4th_thousand/README.md b/paginated_contents/algorithms/4th_thousand/README.md index 48ebbd7a0a..a305a10a0c 100644 --- a/paginated_contents/algorithms/4th_thousand/README.md +++ b/paginated_contents/algorithms/4th_thousand/README.md @@ -1,5 +1,6 @@ | # | Title | Solutions | Video | Difficulty | Tag |------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|---------------------------------------------------------------------- +| 3502 | [Minimum Cost to Reach Every Position](https://leetcode.com/problems/minimum-cost-to-reach-every-position/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3502.java) | | Easy | | 3471 | [Find the Largest Almost Missing Integer](https://leetcode.com/problems/find-the-largest-almost-missing-integer/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3471.java) | | Easy | | 3396 | [Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java) | | Easy | | 3392 | [Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3392.java) | | Easy | diff --git a/src/main/java/com/fishercoder/solutions/fourththousand/_3502.java b/src/main/java/com/fishercoder/solutions/fourththousand/_3502.java new file mode 100644 index 0000000000..98c94c7726 --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/fourththousand/_3502.java @@ -0,0 +1,17 @@ +package com.fishercoder.solutions.fourththousand; + +public class _3502 { + public static class Solution1 { + public int[] minCosts(int[] cost) { + int[] res = new int[cost.length]; + int min = cost[0]; + for (int i = 0; i < cost.length; i++) { + if (cost[i] < min) { + min = cost[i]; + } + res[i] = min; + } + return res; + } + } +} diff --git a/src/test/java/com/fishercoder/fourththousand/_3502Test.java b/src/test/java/com/fishercoder/fourththousand/_3502Test.java new file mode 100644 index 0000000000..0e468c97b1 --- /dev/null +++ b/src/test/java/com/fishercoder/fourththousand/_3502Test.java @@ -0,0 +1,22 @@ +package com.fishercoder.fourththousand; + +import com.fishercoder.solutions.fourththousand._3502; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + +public class _3502Test { + private _3502.Solution1 solution1; + + @BeforeEach + public void setup() { + solution1 = new _3502.Solution1(); + } + + @Test + public void test1() { + assertArrayEquals(new int[]{5, 3, 3, 1, 1, 1}, solution1.minCosts(new int[]{5, 3, 4, 1, 3, 2})); + } + +} From f557f7baa36a7d974b0989936787bc2d4181cbe1 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Mon, 31 Mar 2025 15:05:48 -0700 Subject: [PATCH 06/13] [LEET-3502] fix unit test --- .../java/com/fishercoder/fourththousand/_3502Test.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/fishercoder/fourththousand/_3502Test.java b/src/test/java/com/fishercoder/fourththousand/_3502Test.java index 0e468c97b1..7159fef0c3 100644 --- a/src/test/java/com/fishercoder/fourththousand/_3502Test.java +++ b/src/test/java/com/fishercoder/fourththousand/_3502Test.java @@ -1,11 +1,11 @@ package com.fishercoder.fourththousand; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + import com.fishercoder.solutions.fourththousand._3502; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; - public class _3502Test { private _3502.Solution1 solution1; @@ -16,7 +16,7 @@ public void setup() { @Test public void test1() { - assertArrayEquals(new int[]{5, 3, 3, 1, 1, 1}, solution1.minCosts(new int[]{5, 3, 4, 1, 3, 2})); + assertArrayEquals( + new int[] {5, 3, 3, 1, 1, 1}, solution1.minCosts(new int[] {5, 3, 4, 1, 3, 2})); } - } From defdfd05639bb2e2a3f4cc6f277fc872a5974063 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 6 Apr 2025 19:57:56 -0700 Subject: [PATCH 07/13] [LEET-3402] add 3402 --- .../algorithms/4th_thousand/README.md | 1 + .../solutions/fourththousand/_3402.java | 18 +++++++++++++++ .../fishercoder/fourththousand/_3402Test.java | 22 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/fourththousand/_3402.java create mode 100644 src/test/java/com/fishercoder/fourththousand/_3402Test.java diff --git a/paginated_contents/algorithms/4th_thousand/README.md b/paginated_contents/algorithms/4th_thousand/README.md index a305a10a0c..835c3e4faa 100644 --- a/paginated_contents/algorithms/4th_thousand/README.md +++ b/paginated_contents/algorithms/4th_thousand/README.md @@ -2,6 +2,7 @@ |------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|---------------------------------------------------------------------- | 3502 | [Minimum Cost to Reach Every Position](https://leetcode.com/problems/minimum-cost-to-reach-every-position/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3502.java) | | Easy | | 3471 | [Find the Largest Almost Missing Integer](https://leetcode.com/problems/find-the-largest-almost-missing-integer/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3471.java) | | Easy | +| 3402 | [Minimum Operations to Make Columns Strictly Increasing](https://leetcode.com/problems/minimum-operations-to-make-columns-strictly-increasing/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3402.java) | | Easy | | 3396 | [Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java) | | Easy | | 3392 | [Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3392.java) | | Easy | | 3386 | [Button with Longest Push Time](https://leetcode.com/problems/button-with-longest-push-time/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3386.java) | | Easy | diff --git a/src/main/java/com/fishercoder/solutions/fourththousand/_3402.java b/src/main/java/com/fishercoder/solutions/fourththousand/_3402.java new file mode 100644 index 0000000000..88e07e77ea --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/fourththousand/_3402.java @@ -0,0 +1,18 @@ +package com.fishercoder.solutions.fourththousand; + +public class _3402 { + public static class Solution1 { + public int minimumOperations(int[][] grid) { + int ops = 0; + for (int j = 0; j < grid[0].length; j++) { + for (int i = 1; i < grid.length; i++) { + if (grid[i][j] <= grid[i - 1][j]) { + ops += grid[i - 1][j] - grid[i][j] + 1; + grid[i][j] = grid[i - 1][j] + 1; + } + } + } + return ops; + } + } +} diff --git a/src/test/java/com/fishercoder/fourththousand/_3402Test.java b/src/test/java/com/fishercoder/fourththousand/_3402Test.java new file mode 100644 index 0000000000..c7ae0df5bb --- /dev/null +++ b/src/test/java/com/fishercoder/fourththousand/_3402Test.java @@ -0,0 +1,22 @@ +package com.fishercoder.fourththousand; + +import com.fishercoder.common.utils.CommonUtils; +import com.fishercoder.solutions.fourththousand._3402; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class _3402Test { + private _3402.Solution1 solution1; + + @BeforeEach + public void setup() { + solution1 = new _3402.Solution1(); + } + + @Test + public void test1() { + assertEquals(15, solution1.minimumOperations(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[3,2],[1,3],[3,4],[0,1]"))); + } +} From 9db17c3ca3edc2cd86a62199b9a80bee164d6f35 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 6 Apr 2025 19:59:02 -0700 Subject: [PATCH 08/13] [LEET-3402] fix unit test --- .../java/com/fishercoder/fourththousand/_3402Test.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/fishercoder/fourththousand/_3402Test.java b/src/test/java/com/fishercoder/fourththousand/_3402Test.java index c7ae0df5bb..37a664802e 100644 --- a/src/test/java/com/fishercoder/fourththousand/_3402Test.java +++ b/src/test/java/com/fishercoder/fourththousand/_3402Test.java @@ -1,12 +1,12 @@ package com.fishercoder.fourththousand; +import static org.junit.jupiter.api.Assertions.assertEquals; + import com.fishercoder.common.utils.CommonUtils; import com.fishercoder.solutions.fourththousand._3402; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class _3402Test { private _3402.Solution1 solution1; @@ -17,6 +17,10 @@ public void setup() { @Test public void test1() { - assertEquals(15, solution1.minimumOperations(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[3,2],[1,3],[3,4],[0,1]"))); + assertEquals( + 15, + solution1.minimumOperations( + CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray( + "[3,2],[1,3],[3,4],[0,1]"))); } } From 9dc004778d1b4d4e151ebeb13c490c9c8a128ea0 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 27 Apr 2025 14:56:03 -0700 Subject: [PATCH 09/13] [LEET-3491] add 3491 --- .../algorithms/4th_thousand/README.md | 1 + .../solutions/fourththousand/_3491.java | 16 ++++++++++++++ .../fishercoder/fourththousand/_3491Test.java | 21 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/fourththousand/_3491.java create mode 100644 src/test/java/com/fishercoder/fourththousand/_3491Test.java diff --git a/paginated_contents/algorithms/4th_thousand/README.md b/paginated_contents/algorithms/4th_thousand/README.md index 835c3e4faa..424a1eedf5 100644 --- a/paginated_contents/algorithms/4th_thousand/README.md +++ b/paginated_contents/algorithms/4th_thousand/README.md @@ -1,6 +1,7 @@ | # | Title | Solutions | Video | Difficulty | Tag |------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|---------------------------------------------------------------------- | 3502 | [Minimum Cost to Reach Every Position](https://leetcode.com/problems/minimum-cost-to-reach-every-position/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3502.java) | | Easy | +| 3491 | [Phone Number Prefix](https://leetcode.com/problems/phone-number-prefix/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3491.java) | | Easy | | 3471 | [Find the Largest Almost Missing Integer](https://leetcode.com/problems/find-the-largest-almost-missing-integer/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3471.java) | | Easy | | 3402 | [Minimum Operations to Make Columns Strictly Increasing](https://leetcode.com/problems/minimum-operations-to-make-columns-strictly-increasing/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3402.java) | | Easy | | 3396 | [Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java) | | Easy | diff --git a/src/main/java/com/fishercoder/solutions/fourththousand/_3491.java b/src/main/java/com/fishercoder/solutions/fourththousand/_3491.java new file mode 100644 index 0000000000..fecbad9937 --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/fourththousand/_3491.java @@ -0,0 +1,16 @@ +package com.fishercoder.solutions.fourththousand; + +public class _3491 { + public static class Solution1 { + public boolean phonePrefix(String[] numbers) { + for (int i = 0; i < numbers.length; i++) { + for (int j = 0; j < numbers.length; j++) { + if (i != j && numbers[i].startsWith(numbers[j])) { + return false; + } + } + } + return true; + } + } +} diff --git a/src/test/java/com/fishercoder/fourththousand/_3491Test.java b/src/test/java/com/fishercoder/fourththousand/_3491Test.java new file mode 100644 index 0000000000..08a21eeddc --- /dev/null +++ b/src/test/java/com/fishercoder/fourththousand/_3491Test.java @@ -0,0 +1,21 @@ +package com.fishercoder.fourththousand; + +import com.fishercoder.solutions.fourththousand._3491; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class _3491Test { + private _3491.Solution1 solution1; + + @BeforeEach + public void setup() { + solution1 = new _3491.Solution1(); + } + + @Test + public void test1() { + assertEquals(true, solution1.phonePrefix(new String[]{"1", "2", "4", "3"})); + } +} From 7b5462190632d157c9f010931b73a00c35afeada Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 27 Apr 2025 14:58:41 -0700 Subject: [PATCH 10/13] [LEET-3491] fix unit test --- src/test/java/com/fishercoder/fourththousand/_3491Test.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/fishercoder/fourththousand/_3491Test.java b/src/test/java/com/fishercoder/fourththousand/_3491Test.java index 08a21eeddc..2e8d934bed 100644 --- a/src/test/java/com/fishercoder/fourththousand/_3491Test.java +++ b/src/test/java/com/fishercoder/fourththousand/_3491Test.java @@ -1,11 +1,11 @@ package com.fishercoder.fourththousand; +import static org.junit.jupiter.api.Assertions.assertEquals; + import com.fishercoder.solutions.fourththousand._3491; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class _3491Test { private _3491.Solution1 solution1; @@ -16,6 +16,6 @@ public void setup() { @Test public void test1() { - assertEquals(true, solution1.phonePrefix(new String[]{"1", "2", "4", "3"})); + assertEquals(true, solution1.phonePrefix(new String[] {"1", "2", "4", "3"})); } } From dd67dd385c03586cb9169e82b10d9a7149dfa587 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Sun, 27 Apr 2025 15:29:23 -0700 Subject: [PATCH 11/13] [LEET-3477] add 3477 --- .../algorithms/4th_thousand/README.md | 1 + .../solutions/fourththousand/_3477.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/fourththousand/_3477.java diff --git a/paginated_contents/algorithms/4th_thousand/README.md b/paginated_contents/algorithms/4th_thousand/README.md index 424a1eedf5..5237fed1ea 100644 --- a/paginated_contents/algorithms/4th_thousand/README.md +++ b/paginated_contents/algorithms/4th_thousand/README.md @@ -2,6 +2,7 @@ |------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|---------------------------------------------------------------------- | 3502 | [Minimum Cost to Reach Every Position](https://leetcode.com/problems/minimum-cost-to-reach-every-position/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3502.java) | | Easy | | 3491 | [Phone Number Prefix](https://leetcode.com/problems/phone-number-prefix/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3491.java) | | Easy | +| 3477 | [Fruits Into Baskets II](https://leetcode.com/problems/fruits-into-baskets-ii/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3477.java) | | Easy | | 3471 | [Find the Largest Almost Missing Integer](https://leetcode.com/problems/find-the-largest-almost-missing-integer/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3471.java) | | Easy | | 3402 | [Minimum Operations to Make Columns Strictly Increasing](https://leetcode.com/problems/minimum-operations-to-make-columns-strictly-increasing/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3402.java) | | Easy | | 3396 | [Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java) | | Easy | diff --git a/src/main/java/com/fishercoder/solutions/fourththousand/_3477.java b/src/main/java/com/fishercoder/solutions/fourththousand/_3477.java new file mode 100644 index 0000000000..f2054202fa --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/fourththousand/_3477.java @@ -0,0 +1,24 @@ +package com.fishercoder.solutions.fourththousand; + +public class _3477 { + public static class Solution1 { + public int numOfUnplacedFruits(int[] fruits, int[] baskets) { + for (int i = 0; i < fruits.length; i++) { + for (int j = 0; j < baskets.length; j++) { + if (fruits[i] <= baskets[j]) { + baskets[j] = -1; + fruits[i] = -1; + break; + } + } + } + int count = 0; + for (int i = 0; i < fruits.length; i++) { + if (fruits[i] > -1) { + count++; + } + } + return count; + } + } +} From 3636dab621e3e304571ac065725101a5f178c3e5 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Thu, 19 Jun 2025 08:09:03 -0700 Subject: [PATCH 12/13] [LEET-3450] add 3450 --- .../algorithms/4th_thousand/README.md | 1 + .../solutions/fourththousand/_3450.java | 24 +++++++++++++++++++ .../fishercoder/fourththousand/_3450Test.java | 22 +++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/fourththousand/_3450.java create mode 100644 src/test/java/com/fishercoder/fourththousand/_3450Test.java diff --git a/paginated_contents/algorithms/4th_thousand/README.md b/paginated_contents/algorithms/4th_thousand/README.md index 5237fed1ea..b710e12009 100644 --- a/paginated_contents/algorithms/4th_thousand/README.md +++ b/paginated_contents/algorithms/4th_thousand/README.md @@ -4,6 +4,7 @@ | 3491 | [Phone Number Prefix](https://leetcode.com/problems/phone-number-prefix/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3491.java) | | Easy | | 3477 | [Fruits Into Baskets II](https://leetcode.com/problems/fruits-into-baskets-ii/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3477.java) | | Easy | | 3471 | [Find the Largest Almost Missing Integer](https://leetcode.com/problems/find-the-largest-almost-missing-integer/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3471.java) | | Easy | +| 3450 | [Maximum Students on a Single Bench](https://leetcode.com/problems/maximum-students-on-a-single-bench/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3450.java) | | Easy | | 3402 | [Minimum Operations to Make Columns Strictly Increasing](https://leetcode.com/problems/minimum-operations-to-make-columns-strictly-increasing/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3402.java) | | Easy | | 3396 | [Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java) | | Easy | | 3392 | [Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3392.java) | | Easy | diff --git a/src/main/java/com/fishercoder/solutions/fourththousand/_3450.java b/src/main/java/com/fishercoder/solutions/fourththousand/_3450.java new file mode 100644 index 0000000000..d24c051d61 --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/fourththousand/_3450.java @@ -0,0 +1,24 @@ +package com.fishercoder.solutions.fourththousand; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class _3450 { + public static class Solution1 { + public int maxStudentsOnBench(int[][] students) { + Map> map = new HashMap<>(); + for (int[] student : students) { + Set set = map.getOrDefault(student[1], new HashSet<>()); + set.add(student[0]); + map.put(student[1], set); + } + int result = 0; + for (Map.Entry> entry : map.entrySet()) { + result = Math.max(result, entry.getValue().size()); + } + return result; + } + } +} diff --git a/src/test/java/com/fishercoder/fourththousand/_3450Test.java b/src/test/java/com/fishercoder/fourththousand/_3450Test.java new file mode 100644 index 0000000000..f427a6819f --- /dev/null +++ b/src/test/java/com/fishercoder/fourththousand/_3450Test.java @@ -0,0 +1,22 @@ +package com.fishercoder.fourththousand; + +import com.fishercoder.common.utils.CommonUtils; +import com.fishercoder.solutions.fourththousand._3450; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class _3450Test { + private _3450.Solution1 solution1; + + @BeforeEach + public void setup() { + solution1 = new _3450.Solution1(); + } + + @Test + public void test1() { + assertEquals(3, solution1.maxStudentsOnBench(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[1,2],[2,2],[3,3],[1,3],[2,3]"))); + } +} From df7a9cba9df4cdaefd1a0d5b343661ba2ca2810b Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Thu, 19 Jun 2025 08:10:45 -0700 Subject: [PATCH 13/13] [LEET-3450] fix build --- .../java/com/fishercoder/fourththousand/_3450Test.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/fishercoder/fourththousand/_3450Test.java b/src/test/java/com/fishercoder/fourththousand/_3450Test.java index f427a6819f..be698b7186 100644 --- a/src/test/java/com/fishercoder/fourththousand/_3450Test.java +++ b/src/test/java/com/fishercoder/fourththousand/_3450Test.java @@ -1,12 +1,12 @@ package com.fishercoder.fourththousand; +import static org.junit.jupiter.api.Assertions.assertEquals; + import com.fishercoder.common.utils.CommonUtils; import com.fishercoder.solutions.fourththousand._3450; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class _3450Test { private _3450.Solution1 solution1; @@ -17,6 +17,10 @@ public void setup() { @Test public void test1() { - assertEquals(3, solution1.maxStudentsOnBench(CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[1,2],[2,2],[3,3],[1,3],[2,3]"))); + assertEquals( + 3, + solution1.maxStudentsOnBench( + CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray( + "[1,2],[2,2],[3,3],[1,3],[2,3]"))); } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy