Tap here to switch tabs
Problem
Submissions

Problem: Get Watched Videos by Your Friends

Try to solve the Get Watched Videos by Your Friends problem.

Statement

There are nn people, represented by an integer 00 to n−1n - 1. You are given a 22D array of strings watchedVideos where watchedVideos[i] is the list of videos watched by person i, and a 22D array of integers friends where friends[i] contains the IDs of the direct friends of person i.

Friendship is mutual, meaning if person i is friends with person j, then person j is friends with person i.

Given an integer id representing your person ID and an integer level, determine the list of videos watched by all people whose shortest distance to you in the friendship network is exactly equal to level.

Return the list of videos sorted by their total view frequency in ascending order. If multiple videos have the same frequency, sort them in lexicographical order.

Constraints:

  • n ==== watchedVideos.length ==== friends.length

  • 2≤n≤1002 \leq n \leq 100

  • 1≤1 \leq watchedVideos[i].length ≤100\leq 100

  • 1≤1 \leq watchedVideos[i][j].length ≤8\leq 8

  • 0≤0 \leq friends[i].length <n< n

  • 0≤0 \leq friends[i][j] <n< n

  • 0≤0 \leq id <n< n

  • 1≤1 \leq level <n< n

  • If friends[i] contains j, then friends[j] contains i.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Get Watched Videos by Your Friends

Try to solve the Get Watched Videos by Your Friends problem.

Statement

There are nn people, represented by an integer 00 to n−1n - 1. You are given a 22D array of strings watchedVideos where watchedVideos[i] is the list of videos watched by person i, and a 22D array of integers friends where friends[i] contains the IDs of the direct friends of person i.

Friendship is mutual, meaning if person i is friends with person j, then person j is friends with person i.

Given an integer id representing your person ID and an integer level, determine the list of videos watched by all people whose shortest distance to you in the friendship network is exactly equal to level.

Return the list of videos sorted by their total view frequency in ascending order. If multiple videos have the same frequency, sort them in lexicographical order.

Constraints:

  • n ==== watchedVideos.length ==== friends.length

  • 2≤n≤1002 \leq n \leq 100

  • 1≤1 \leq watchedVideos[i].length ≤100\leq 100

  • 1≤1 \leq watchedVideos[i][j].length ≤8\leq 8

  • 0≤0 \leq friends[i].length <n< n

  • 0≤0 \leq friends[i][j] <n< n

  • 0≤0 \leq id <n< n

  • 1≤1 \leq level <n< n

  • If friends[i] contains j, then friends[j] contains i.