Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions leetcode3/최원준/1311. Get Watched Videos by Your Friends.py
Original file line number Diff line number Diff line change
@@ -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))
Loading