A community mentorship program keeps a running log of every mentoring session it holds. Each log entry records the mentor who ran the session, the skill that was taught, and the cohort the session belonged to. The same mentor may end up teaching the same skill again in a different cohort, and that should not be counted twice. For every mentor who appears anywhere in the log, the program wants to know how many distinct skills that mentor has taught in total, across every cohort combined.
Line 1: an integer n -- the number of log entries.
Next n lines: each contains three integers mentor_id, skill_id, cohort_id -- one mentoring session.
Print one line for every distinct mentor_id that appears in the log, sorted by mentor_id ascending. Each line contains mentor_id followed by a single space and the number of distinct skill_id values that mentor taught (counted once no matter how many cohorts or log entries repeat it).
Example 1
Input
3 1 2 3 1 2 4 1 3 3
Expected
1 2
Explanation
Mentor 1 taught skill 2 in cohort 3, skill 2 again in cohort 4 (same skill, different cohort -- counted once), and skill 3 in cohort 3, so mentor 1 has 2 distinct skills. The output is a single line: "1 2".
Example 2
Input
4 1 2 1 2 3 1 2 3 2 2 4 1
Expected
1 1 2 2
Explanation
Mentor 1 taught skill 2 once, giving 1 distinct skill. Mentor 2 taught skill 3 in cohort 1, skill 3 again in cohort 2 (a duplicate, not counted twice), and skill 4 in cohort 1, giving 2 distinct skills. Sorted by mentor_id, the output is "1 1" followed by "2 2".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →