Recommend videos watched by friends at a given friendship distance, ordered by frequency and then name.
Given a list of each person's watched videos and an undirected friendship graph, find the videos watched by people who are exactly friendship steps away from a given person.
Collect all videos watched by those friends, count how many times each video appears, and return the videos sorted by:
This is a graph traversal and aggregation problem that combines distance-limited search with frequency-based sorting.
watchedVideos, where watchedVideos[i] is the list of videos watched by person i.friends, where friends[i] contains the direct friends of person i.id for the starting person.k for the friendship distance.id is exactly k.0 <= id < nk >= 0Example 1
Input
watchedVideos = [["A","B"],["C"],["B","C"],["D"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, k = 2
Output
["D"]
Explanation
At distance 2 from person 0 is person 3. Person 3 watched only video D, so the answer is ["D"].
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.