Skip to content

Commit 08cfa78

Browse files
committed
Add solution #3450
1 parent d12594a commit 08cfa78

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,6 +2699,7 @@
26992699
3442|[Maximum Difference Between Even and Odd Frequency I](./solutions/3442-maximum-difference-between-even-and-odd-frequency-i.js)|Easy|
27002700
3443|[Maximum Manhattan Distance After K Changes](./solutions/3443-maximum-manhattan-distance-after-k-changes.js)|Medium|
27012701
3445|[Maximum Difference Between Even and Odd Frequency II](./solutions/3445-maximum-difference-between-even-and-odd-frequency-ii.js)|Hard|
2702+
3450|[Maximum Students on a Single Bench](./solutions/3450-maximum-students-on-a-single-bench.js)|Easy|
27022703
3452|[Sum of Good Numbers](./solutions/3452-sum-of-good-numbers.js)|Easy|
27032704
3461|[Check If Digits Are Equal in String After Operations I](./solutions/3461-check-if-digits-are-equal-in-string-after-operations-i.js)|Easy|
27042705
3462|[Maximum Sum With at Most K Elements](./solutions/3462-maximum-sum-with-at-most-k-elements.js)|Medium|
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* 3450. Maximum Students on a Single Bench
3+
* https://leetcode.com/problems/maximum-students-on-a-single-bench/
4+
* Difficulty: Easy
5+
*
6+
* You are given a 2D integer array of student data students, where
7+
* students[i] = [student_id, bench_id] represents that student student_id is
8+
* sitting on the bench bench_id.
9+
*
10+
* Return the maximum number of unique students sitting on any single bench. If no
11+
* students are present, return 0.
12+
*
13+
* Note: A student can appear multiple times on the same bench in the input, but
14+
* they should be counted only once per bench.
15+
*/
16+
17+
/**
18+
* @param {number[][]} students
19+
* @return {number}
20+
*/
21+
var maxStudentsOnBench = function(students) {
22+
const map = new Map();
23+
24+
for (const [studentId, benchId] of students) {
25+
if (!map.has(benchId)) {
26+
map.set(benchId, new Set());
27+
}
28+
map.get(benchId).add(studentId);
29+
}
30+
31+
let result = 0;
32+
for (const studentSet of map.values()) {
33+
result = Math.max(result, studentSet.size);
34+
}
35+
36+
return result;
37+
};

0 commit comments

Comments
 (0)
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