Get Watched Videos by Your Friends LeetCode solution in Python
1class Solution:2def watchedVideosByFriends(3self,4watchedVideos: List[List[str]],5friends: List[List[int]],6id: int,7level: int,8) -> List[str]:9q = [id]10vis = set([id])11l = 012while l < level:13new_q = []14for x in q:15for friend in friends[x]:16if not friend in vis:17vis.add(friend)18new_q.append(friend)19q = new_q20l += 121a = Counter()22for x in q:23for vids in watchedVideos[x]:24a[vids] += 125A = sorted([[a[x], x] for x in a])26return [x[1] for x in A]