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..be698b7186 --- /dev/null +++ b/src/test/java/com/fishercoder/fourththousand/_3450Test.java @@ -0,0 +1,26 @@ +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; + +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]"))); + } +} 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