Count Students Who Completed All Assignments - Problem
You are given a 2D integer array submissions where submissions[i] = [studentId, assignmentId] represents that a student submitted an assignment, and an integer totalAssignments representing the total number of assignments.
A student has completed all assignments if they have submissions for every assignment from 0 to totalAssignments - 1.
Return the number of students who completed all assignments.
Input & Output
Example 1 — Basic Case
$
Input:
submissions = [[1,0],[1,1],[1,2],[2,0],[2,1],[3,0],[3,1],[3,2]], totalAssignments = 3
›
Output:
2
💡 Note:
Student 1 submitted {0,1,2} ✅, Student 2 submitted {0,1} ❌ missing 2, Student 3 submitted {0,1,2} ✅. Two students completed all 3 assignments.
Example 2 — No One Completed
$
Input:
submissions = [[5,0],[5,2],[8,1],[8,2]], totalAssignments = 3
›
Output:
0
💡 Note:
Student 5 is missing assignment 1, Student 8 is missing assignment 0. Neither completed all 3 assignments.
Example 3 — Duplicate Submissions Ignored
$
Input:
submissions = [[1,0],[1,0],[1,1],[2,0],[2,1]], totalAssignments = 2
›
Output:
2
💡 Note:
Student 1's duplicate submission for assignment 0 doesn't matter. Both students submitted assignments 0 and 1, completing all required.
Constraints
- 1 ≤ submissions.length ≤ 10⁴
- 1 ≤ totalAssignments ≤ 26
- 0 ≤ studentId ≤ 10⁴
- 0 ≤ assignmentId < totalAssignments
- submissions[i].length == 2
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code