101
0/304
Loading content...
A university analytics team stores teaching assignments in the Teacher table:
Data rule:
Task: For each teacher_id, compute how many distinct subject_id values that teacher teaches.
Output requirements:
Supported submission environments:
Teacher:
| 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":1,"cnt":2},
{"teacher_id":2,"cnt":4}
]Teacher 1 appears twice for subject 2 in different departments, but that subject is counted once. Teacher 2 teaches four different subjects.
Teacher:
| teacher_id | subject_id | dept_id |
|------------|------------|---------|
| 10 | 100 | 1 |
| 10 | 100 | 2 |
| 10 | 101 | 3 |
| 11 | 100 | 3 |
| 11 | 102 | 4 |
| 12 | 103 | 5 |
| 12 | 103 | 6 |[
{"teacher_id":10,"cnt":2},
{"teacher_id":11,"cnt":2},
{"teacher_id":12,"cnt":1}
]Shared subject IDs across different teachers are counted independently for each teacher.
Teacher:
| teacher_id | subject_id | dept_id |
|------------|------------|---------|
| 42 | 900 | 10 |
| 42 | 901 | 10 |
| 42 | 902 | 11 |
| 42 | 900 | 12 |[
{"teacher_id":42,"cnt":3}
]Even with four assignment rows, subject 900 is duplicated for the same teacher and contributes only one unique subject.
Constraints