From 2c427329409f194ca0316dfce35292c0cb37573b Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Sat, 17 Oct 2026 23:22:06 +0900 Subject: [PATCH] Create 1311. Get Watched Videos by Your Friends.py --- ...11. Get Watched Videos by Your Friends.py" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1311. Get Watched Videos by Your Friends.py" 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))