A community recording studio logs every booking session it hosts. Each log entry records the id of the studio booth used and the format of that session, which is always exactly one of two words: "Mixing" or "Tracking". A studio booth is called dual-format if, somewhere across all of its logged sessions, it has hosted at least one "Mixing" session and at least one "Tracking" session. Given the full booking log, report every dual-format studio booth, in ascending order of id, together with the two format names it has hosted written as a single comma-separated string with the format names in alphabetical order.
Line 1: an integer n — the number of booking log entries. Next n lines: each contains an integer boothId followed by a space and a format string that is exactly "Mixing" or "Tracking".
Print one line for every dual-format studio booth, sorted by boothId in ascending numeric order, in the form: boothId format1,format2 where format1,format2 is the two format names joined by a comma in alphabetical order (this is always "Mixing,Tracking"). Print nothing if no booth is dual-format.
0 <= n <= 10^5 1 <= boothId <= 10^9 format is exactly the string "Mixing" or "Tracking" (case-sensitive). The same (boothId, format) pair may appear more than once in the log.
Example 1
Input
3 101 Mixing 101 Tracking 102 Mixing
Expected
101 Mixing,Tracking
Explanation
Booth 101 has one 'Mixing' entry and one 'Tracking' entry, so it qualifies and is reported as '101 Mixing,Tracking'. Booth 102 only ever appears with 'Mixing', so it is not dual-format and is omitted from the output.
Example 2
Input
5 7 Tracking 7 Tracking 9 Mixing 9 Tracking 15 Mixing
Expected
9 Mixing,Tracking
Explanation
Booth 7 has two log entries, but both are 'Tracking', so it never qualifies. Booth 9 has one 'Mixing' entry and one 'Tracking' entry, so it qualifies. Booth 15 only has 'Mixing'. Only booth 9 is dual-format, printed as '9 Mixing,Tracking'.
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 →