File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 2699
2699
3442|[ Maximum Difference Between Even and Odd Frequency I] ( ./solutions/3442-maximum-difference-between-even-and-odd-frequency-i.js ) |Easy|
2700
2700
3443|[ Maximum Manhattan Distance After K Changes] ( ./solutions/3443-maximum-manhattan-distance-after-k-changes.js ) |Medium|
2701
2701
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|
2702
2703
3452|[ Sum of Good Numbers] ( ./solutions/3452-sum-of-good-numbers.js ) |Easy|
2703
2704
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|
2704
2705
3462|[ Maximum Sum With at Most K Elements] ( ./solutions/3462-maximum-sum-with-at-most-k-elements.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments