Practice Number of Unique Subjects Taught by Each Teacher
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Tables: Teacher(teacher_id INT, subject_id INT, dept_id INT). Teacher has key (subject_id, dept_id). A row identifies who teaches a subject in a department. Return teacher_id and cnt, the number of distinct subject_id values taught by that teacher across all departments. Teaching one subject in several departments counts once. Output order is unrestricted.
Source: Number of Unique Subjects Taught by Each Teacher on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Teacher table: +------------+------------+---------+ | teacher_id | subject_id | dept_id | +------------+------------+---------+ | 1 | 2 | 3 | | 1 | 2 | 4 | | 1 | 3 | 3 | | 2 | 1 | 1 | | 2 | 2 | 1 | | 2 | 3 | 1 | | 2 | 4 | 1 | +------------+------------+---------+
+------------+-----+ | teacher_id | cnt | +------------+-----+ | 1 | 2 | | 2 | 4 | +------------+-----+
Related LeetCode Problems
Practice more problems similar to Number of Unique Subjects Taught by Each Teacher.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.