Video Frequencies at One Exact Friendship Distance

Quick Overview

Video Frequencies at One Exact Friendship Distance. The arrays give each person's watched-video list and symmetric friendship neighbors.

Video Frequencies at One Exact Friendship Distance

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem The arrays give each person's watched-video list and symmetric friendship neighbors. Starting from id, consider only people whose shortest friendship distance is exactly level. Return their video titles once each, ordered by increasing total frequency in those lists and then alphabetically for tied frequencies. ```cpp class Solution { public: vector<string> watchedVideosByFriends(vector<vector<string>>& watchedVideos, vector<vector<int>>& friends, int id, int level); }; ``` ### Examples **Example 1:** ```text Input: watchedVideos = [["self"],["x","a"],["x","b"]], friends = [[1,2],[0],[0]], id = 0, level = 1 Output: ["a","b","x"] Explanation: a and b occur once each, and x occurs twice among the two distance-one people. ``` **Example 2:** ```text Input: watchedVideos = [["q"],["b"],["a"]], friends = [[1],[0,2],[1]], id = 0, level = 2 Output: ["a"] Explanation: Only person2 has shortest distance2. ``` ### Constraints - Both outer arrays have length n, with `2 <= n <= 100`. - Each watched list has 1 to 100 titles; each title has length 1 to 8. - Each friend list has 0 to n-1 entries, all valid person labels. - `0 <= id < n` and `1 <= level < n`. - Every listed friendship is symmetric. ### Contract considerations Friendships are symmetric. No uniqueness promise within watched lists is invented; frequencies count the supplied selected-list entries. ```hint Read the boundary condition Distinguish the exact shortest friendship distance from longer walks. Include frequency ties and a distance with no qualifying people. ``` ### Boundary reminders Friendships are symmetric. No uniqueness promise within watched lists is invented; frequencies count the supplied selected-list entries.

Overview: Video Frequencies at One Exact Friendship Distance. The arrays give each person's watched-video list and symmetric friendship neighbors.

Amazon logo
Amazon
Aug 22, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

The arrays give each person's watched-video list and symmetric friendship neighbors. Starting from id, consider only people whose shortest friendship distance is exactly level. Return their video titles once each, ordered by increasing total frequency in those lists and then alphabetically for tied frequencies.

class Solution {
public:
    vector<string> watchedVideosByFriends(vector<vector<string>>& watchedVideos, vector<vector<int>>& friends, int id, int level);
};

Examples

Example 1:

Input: watchedVideos = [["self"],["x","a"],["x","b"]], friends = [[1,2],[0],[0]], id = 0, level = 1
Output: ["a","b","x"]
Explanation: a and b occur once each, and x occurs twice among the two distance-one people.

Example 2:

Input: watchedVideos = [["q"],["b"],["a"]], friends = [[1],[0,2],[1]], id = 0, level = 2
Output: ["a"]
Explanation: Only person2 has shortest distance2.

Constraints

  • Both outer arrays have length n, with 2 <= n <= 100 .
  • Each watched list has 1 to 100 titles; each title has length 1 to 8.
  • Each friend list has 0 to n-1 entries, all valid person labels.
  • 0 <= id < n and 1 <= level < n .
  • Every listed friendship is symmetric.

Contract considerations

Friendships are symmetric. No uniqueness promise within watched lists is invented; frequencies count the supplied selected-list entries.

Boundary reminders

Friendships are symmetric. No uniqueness promise within watched lists is invented; frequencies count the supplied selected-list entries.