n people numbered 0 to n - 1. watched[i] lists the videos person i has watched, and friends[i] lists their friends (friendship goes both ways).
The distance between two people is the smallest number of friend-to-friend hops needed to get from one to the other. Your friends are at distance 1, friends of friends who aren't your friends are at distance 2, and so on.
For person, gather every video watched by people at exactly distance from them and count how many times each video appears. Return the distinct videos sorted by count, lowest first, breaking ties alphabetically.watched=[["news", "jazz"], ["jazz"], ["film", "news"], ["film"]], friends=[[1], [0, 2], [1, 3], [2]], person=0, distance=2 → ['film', 'news']
The friends form a chain 0–1–2–3. Only person 2 is at distance 2 from person 0; they watched film and news once each, and equal counts go in alphabetical order.
watched=[["news", "jazz"], ["jazz"], ["film", "news"], ["film"]], friends=[[1], [0, 2], [1, 3], [2]], person=1, distance=1 → ['film', 'jazz', 'news']
The direct friends of person 1 are 0 and 2. news shows up twice, film and jazz once each, so news comes last.
len(watched) == len(friends) == nj is in friends[i], then i is in friends[j]watched=[["news", "jazz"], ["jazz"], ["film", "news"], ["film"]], friends=[[1], [0, 2], [1, 3], [2]], person=0, distance=2
['film', 'news']
Run checks the first 3 tests in your browser. Submit checks all 51 tests on the server, hidden ones included.