Maximum Students on a Single Bench - Problem
You are given a 2D integer array students, where students[i] = [student_id, bench_id] represents that student student_id is sitting on bench bench_id.
Return the maximum number of unique students sitting on any single bench.
If no students are present, return 0.
Note: A student can appear multiple times on the same bench in the input, but they should be counted only once per bench.
Input & Output
Example 1 — Basic Case
$
Input:
students = [[1,1],[2,1],[3,2],[1,1],[4,2],[5,3]]
›
Output:
2
💡 Note:
Bench 1 has students {1, 2} (2 unique), Bench 2 has students {3, 4} (2 unique), Bench 3 has student {5} (1 unique). Maximum is 2.
Example 2 — Empty Array
$
Input:
students = []
›
Output:
0
💡 Note:
No students present, return 0.
Example 3 — All Same Bench
$
Input:
students = [[1,5],[2,5],[3,5],[1,5]]
›
Output:
3
💡 Note:
All students sit on bench 5. Unique students are {1, 2, 3}, so return 3.
Constraints
- 0 ≤ students.length ≤ 105
- students[i].length == 2
- 1 ≤ student_id, bench_id ≤ 105
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code