#1311
Get Watched Videos by Your Friends
specialist · 900 · lc medium +31 · verified · 52.2% accepted · 483 likes · top 42%
Description
There are n people, each with a unique ID between 0 and n-1. You are given the arrays watchedVideos and friends, where watchedVideos[i] and friends[i] list the watched videos and friends of the person with id = i.
Videos at level k are all videos watched by people whose shortest path distance to you equals exactly k. Level 1 videos are watched by your direct friends, level 2 by their friends, and so on. Given your id and a level, return the videos at that level sorted by frequency ascending, with ties broken alphabetically.
Example 1:
Input: watchedVideos = [["A","B"],["C"],["B","C"],["D"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 1
Output: ["B","C"]
Explanation:
You have id = 0 (green color in the figure) and your friends are (yellow color in the figure):
Person with id = 1 -> watchedVideos = ["C"]
Person with id = 2 -> watchedVideos = ["B","C"]
The frequencies of watchedVideos by your friends are:
B -> 1
C -> 2
Example 2:
Input: watchedVideos = [["A","B"],["C"],["B","C"],["D"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 2
Output: ["D"]
Explanation:
You have id = 0 (green color in the figure) and the only friend of your friends is the person with id = 3 (yellow color in the figure).
Code
1
2
3