Two friends keep running playlists of the songs they have queued up today, recorded as lists of numeric track IDs; a track can be queued more than once if someone hits repeat. Given both playlists, report two counts: how many entries of the first friend's playlist name a track that shows up at least once somewhere in the second friend's playlist, and how many entries of the second friend's playlist name a track that shows up at least once somewhere in the first friend's playlist. Every entry is counted on its own, even if its track ID also appears elsewhere in the same playlist.
Line 1: an integer n, the length of the first playlist. Line 2: n space-separated integers, the first playlist's track IDs. Line 3: an integer m, the length of the second playlist. Line 4: m space-separated integers, the second playlist's track IDs.
Print two integers separated by a single space: the count for the first playlist followed by the count for the second playlist.
Example 1
Input
5 4 3 2 3 1 6 2 2 5 2 3 6
Expected
3 4
Explanation
Second playlist's distinct tracks are {2,5,3,6}. Scanning the first playlist [4,3,2,3,1]: 4 no, 3 yes, 2 yes, 3 yes, 1 no, giving 3 matches. First playlist's distinct tracks are {4,3,2,1}. Scanning the second playlist [2,2,5,2,3,6]: 2 yes, 2 yes, 5 no, 2 yes, 3 yes, 6 no, giving 4 matches. Output: 3 4.
Example 2
Input
3 3 4 2 3 1 5 6
Expected
0 0
Explanation
The two playlists share no track IDs at all ({3,4,2} versus {1,5,6}), so no entry in either playlist finds a match in the other. Output: 0 0.
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 →