From 3636dab621e3e304571ac065725101a5f178c3e5 Mon Sep 17 00:00:00 2001 From: Fisher Coder Date: Thu, 19 Jun 2025 08:09:03 -0700 Subject: [PATCH 1/2] [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 2/2] [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]"))); } }