java.lang.Object
g1301_1400.s1311_get_watched_videos_by_your_friends.Solution

public class Solution extends Object
1311 - Get Watched Videos by Your Friends.<p>Medium</p> <p>There are <code>n</code> people, each person has a unique <em>id</em> between <code>0</code> and <code>n-1</code>. Given the arrays <code>watchedVideos</code> and <code>friends</code>, where <code>watchedVideos[i]</code> and <code>friends[i]</code> contain the list of watched videos and the list of friends respectively for the person with <code>id = i</code>.</p> <p>Level <strong>1</strong> of videos are all watched videos by your friends, level <strong>2</strong> of videos are all watched videos by the friends of your friends and so on. In general, the level <code>k</code> of videos are all watched videos by people with the shortest path <strong>exactly</strong> equal to <code>k</code> with you. Given your <code>id</code> and the <code>level</code> 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.</p> <p><strong>Example 1:</strong></p> <p><strong><img src="https://assets.leetcode.com/uploads/2020/01/02/leetcode_friends_1.png" alt="" /></strong></p> <p><strong>Input:</strong> watchedVideos = [[&ldquo;A&rdquo;,&ldquo;B&rdquo;],[&ldquo;C&rdquo;],[&ldquo;B&rdquo;,&ldquo;C&rdquo;],[&ldquo;D&rdquo;]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 1</p> <p><strong>Output:</strong> [&ldquo;B&rdquo;,&ldquo;C&rdquo;]</p> <p><strong>Explanation:</strong></p> <p>You have id = 0 (green color in the figure) and your friends are (yellow color in the figure):</p> <p>Person with id = 1 -> watchedVideos = [&ldquo;C&rdquo;]</p> <p>Person with id = 2 -> watchedVideos = [&ldquo;B&rdquo;,&ldquo;C&rdquo;]</p> <p>The frequencies of watchedVideos by your friends are:</p> <p>B -> 1</p> <p>C -> 2</p> <p><strong>Example 2:</strong></p> <p><strong><img src="https://assets.leetcode.com/uploads/2020/01/02/leetcode_friends_2.png" alt="" /></strong></p> <p><strong>Input:</strong> watchedVideos = [[&ldquo;A&rdquo;,&ldquo;B&rdquo;],[&ldquo;C&rdquo;],[&ldquo;B&rdquo;,&ldquo;C&rdquo;],[&ldquo;D&rdquo;]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 2</p> <p><strong>Output:</strong> [&ldquo;D&rdquo;]</p> <p><strong>Explanation:</strong> 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).</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == watchedVideos.length == friends.length</code></li> <li><code>2 <= n <= 100</code></li> <li><code>1 <= watchedVideos[i].length <= 100</code></li> <li><code>1 <= watchedVideos[i][j].length <= 8</code></li> <li><code>0 <= friends[i].length < n</code></li> <li><code>0 <= friends[i][j] < n</code></li> <li><code>0 <= id < n</code></li> <li><code>1 <= level < n</code></li> <li>if <code>friends[i]</code> contains <code>j</code>, then <code>friends[j]</code> contains <code>i</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • watchedVideosByFriends

      public List<String> watchedVideosByFriends(List<List<String>> watchedVideos, int[][] friends, int id, int level)