diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1311. Get Watched Videos by Your Friends.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1311. Get Watched Videos by Your Friends.py" new file mode 100644 index 00000000..01328066 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1311. Get Watched Videos by Your Friends.py" @@ -0,0 +1,30 @@ + +from collections import deque, Counter + +class Solution: + def watchedVideosByFriends( + self, + watchedVideos: list[list[str]], + friends: list[list[int]], + id: int, + level: int + ) -> list[str]: + + queue = deque([id]) + visited = {id} + + for _ in range(level): + for _ in range(len(queue)): + person = queue.popleft() + + for friend in friends[person]: + if friend not in visited: + visited.add(friend) + queue.append(friend) + + count = Counter() + + for person in queue: + count.update(watchedVideos[person]) + + return sorted(count, key=lambda video: (count[video], video))