Recommend Films from Viewers Who Watched Everything You Did
Updated
Problem statement
A streaming service knows which films each existing user has watched: histories[i] is the list of films user i watched. A new user has watched the films in watched.
To recommend films to the new user, look only at the existing users who watched every film in watched (the new user's list is a subset of theirs); skip all other users. For every film that the new user has not watched, count how many of these kept users watched it.
Return the films with a count of at least 1, sorted by count from highest to lowest. Films with the same count are sorted by name in ascending lexicographic order. If there is nothing to recommend, return an empty array.
Function
recommendFilms(histories: String[][], watched: String[]) → String[]Examples
Example 1
histories = [["a","b","c","d","e"],["a","c","d"],["b","c"]]watched = ["a","c"]return = ["d","b","e"]- Users 0 and 1 watched both
aandc, so they are kept. User 2 never watcheda, so it is skipped. - Among the kept users,
dwas watched by 2 users, andbandeby 1 each. bandetie, so they are ordered by name:["d","b","e"].
Example 2
histories = [["x","y"],["y","z"]]watched = []return = ["y","x","z"]- The new user watched nothing, so every user is kept.
yhas 2 viewers;xandzhave 1 each and are ordered by name.
Example 3
histories = [["m","n"],["m"]]watched = ["m","q"]return = []- No user watched
q, so nobody is kept and there is nothing to recommend.
Constraints
1 <= histories.length <= 10000 <= histories[i].length <= 500 <= watched.length <= 50- Every film name is 1 to 10 lowercase English letters or digits.
- The films in each
histories[i]are distinct, and the films inwatchedare distinct.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
- Values Exclusive to the Current UserMeta · PHONE SCREENMeta interview questions
- Count Values Appearing Exactly OnceAgoda · PHONE SCREENAgoda interview questions
- Top Two Users by Total Purchase AmountSnowflake · PHONE SCREENSnowflake interview questions
- Restaurant Vote LeadersZipRecruiter · PHONE SCREEN · ONSITE INTERVIEWZipRecruiter interview questions
- AI Role: Collection with Add and Remove OperationsApple · PHONE SCREENApple interview questions
- Employees With Shared InterestsPalantir · PHONE SCREENPalantir interview questions