Apple iTunes | Phone screen | Unique sets of equivalent songs

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2019-06-19Added By Anonymous
Source: Link

Given a list of matching/equivalent song pairs and a list of unique songs, create unique sets of equivalent songs.


Example 1:

1Input: 2matching pairs: [[1, 2], [2, 3], [5, 6], [4, 6], [2, 7], [3, 8], [9, 10]] 3unique songs: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 4Output: [[1, 2, 3, 7, 8], [4, 5, 6], [9, 10]]


Note that transitivity should be considered.

Comments