1311. Get Watched Videos by Your Friends Medium

@problem@discussion
#Array#Hash Table#Breadth-First Search#Sorting



1/**
2 * [1311] Get Watched Videos by Your Friends
3 *
4 * There are n people, each person has a unique id between 0 and n-1. Given the arrays watchedVideos and friends, where watchedVideos[i] and friends[i] contain the list of watched videos and the list of friends respectively for the person with id = i.
5 * Level 1 of videos are all watched videos by your friends, level 2 of videos are all watched videos by the friends of your friends and so on. In general, the level k of videos are all watched videos by people with the shortest path exactly equal to k with you. Given your id and the level of videos, return the list of videos ordered by their frequencies (increasing). For videos with the same frequency order them alphabetically from least to greatest. 
6 *  
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2020/01/02/leetcode_friends_1.png" style="width: 144px; height: 200px;" />
9 * 
10 * Input: watchedVideos = [["A","B"],["C"],["B","C"],["D"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 1
11 * Output: ["B","C"] 
12 * Explanation: 
13 * You have id = 0 (green color in the figure) and your friends are (yellow color in the figure):
14 * Person with id = 1 -> watchedVideos = ["C"] 
15 * Person with id = 2 -> watchedVideos = ["B","C"] 
16 * The frequencies of watchedVideos by your friends are: 
17 * B -> 1 
18 * C -> 2
19 * 
20 * Example 2:
21 * <img alt="" src="https://assets.leetcode.com/uploads/2020/01/02/leetcode_friends_2.png" style="width: 144px; height: 200px;" />
22 * 
23 * Input: watchedVideos = [["A","B"],["C"],["B","C"],["D"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 2
24 * Output: ["D"]
25 * Explanation: 
26 * 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).
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	n == watchedVideos.length == friends.length
32 * 	2 <= n <= 100
33 * 	1 <= watchedVideos[i].length <= 100
34 * 	1 <= watchedVideos[i][j].length <= 8
35 * 	0 <= friends[i].length < n
36 * 	0 <= friends[i][j] < n
37 * 	0 <= id < n
38 * 	1 <= level < n
39 * 	if friends[i] contains j, then friends[j] contains i
40 * 
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/get-watched-videos-by-your-friends/
45// discuss: https://leetcode.com/problems/get-watched-videos-by-your-friends/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50    pub fn watched_videos_by_friends(watched_videos: Vec<Vec<String>>, friends: Vec<Vec<i32>>, id: i32, level: i32) -> Vec<String> {
51        vec![]
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_1311() {
63    }
64}
65


Back
© 2025 bowen.ge All Rights Reserved.