LeetCode Problem Workspace
Most Popular Video Creator
Identify the most popular video creator by summing views and selecting their top-viewed video with array and hash patterns.
5
Topics
5
Code langs
3
Related
Practice Focus
Medium · Array scanning plus hash lookup
Answer-first summary
Identify the most popular video creator by summing views and selecting their top-viewed video with array and hash patterns.
Ace coding interviews with Interview AiBoxInterview AiBox guidance for Array scanning plus hash lookup
This problem requires summing the total views for each creator and identifying the video with the highest views for that creator. Use a hash table to accumulate views and track the top video per creator. Finally, extract all creators with maximum popularity and select their most viewed video, using lexicographical order when ties occur.
Problem Statement
You are given three arrays: creators, ids, and views, each of length n. Each entry represents a video where creators[i] is the creator's name, ids[i] is the video identifier, and views[i] is the view count. Videos may share ids, but each video is distinct with its own views.
Determine which creators have the highest total views summed across all their videos. For each top creator, return their name and the id of their video with the most views. If multiple videos tie in view count, choose the lexicographically smallest id. Return the results as an array of [creator, topVideoId] pairs.
Examples
Example 1
Input: creators = ["alice","bob","alice","chris"], ids = ["one","two","three","four"], views = [5,10,5,4]
Output: [["alice","one"],["bob","two"]]
The popularity of alice is 5 + 5 = 10. The popularity of bob is 10. The popularity of chris is 4. alice and bob are the most popular creators. For bob, the video with the highest view count is "two". For alice, the videos with the highest view count are "one" and "three". Since "one" is lexicographically smaller than "three", it is included in the answer.
Example 2
Input: creators = ["alice","alice","alice"], ids = ["a","b","c"], views = [1,2,2]
Output: [["alice","b"]]
The videos with id "b" and "c" have the highest view count. Since "b" is lexicographically smaller than "c", it is included in the answer.
Constraints
- n == creators.length == ids.length == views.length
- 1 <= n <= 105
- 1 <= creators[i].length, ids[i].length <= 5
- creators[i] and ids[i] consist only of lowercase English letters.
- 0 <= views[i] <= 105
Solution Approach
Hash Table Accumulation
Scan through creators and views arrays while storing cumulative views per creator in a hash table. At the same time, track each creator's top-viewed video id to simplify tie-breaking later.
Determine Maximum Popularity
After accumulation, iterate through the hash table to identify the maximum total views among all creators. Keep a list of all creators matching this maximum popularity for the final result.
Select Top Video per Creator
For each creator with maximum popularity, select the video with the highest individual views. If multiple videos have equal views, return the lexicographically smallest id to ensure consistent output.
Complexity Analysis
| Metric | Value |
|---|---|
| Time | Depends on the final approach |
| Space | Depends on the final approach |
Time complexity is O(n) for scanning the arrays and populating the hash table. Space complexity is O(n) for storing cumulative views and top videos per creator. Sorting is avoided by lexicographical comparisons during accumulation.
What Interviewers Usually Probe
- Checks if candidate uses hash tables for per-creator aggregation
- Looks for proper handling of ties in video views using lexicographical order
- Wants linear scanning without redundant sorting for performance
Common Pitfalls or Variants
Common pitfalls
- Not handling multiple videos with same id correctly
- Forgetting to compare video ids lexicographically in case of view ties
- Using nested loops instead of hash table accumulation causing TLE on large n
Follow-up variants
- Return only the single most popular creator instead of all ties
- Include a threshold filter for minimum views to consider videos
- Extend to top k creators by popularity instead of just the maximum
FAQ
What is the main pattern for Most Popular Video Creator problem?
The main pattern is array scanning combined with hash table lookup to accumulate views per creator efficiently.
How do I handle videos with the same view count?
Select the lexicographically smallest id among videos that tie for the highest views for a creator.
Can video ids repeat for different creators?
Yes, ids may repeat, but each video is distinct and counted individually in view totals.
What is the expected time complexity?
A single pass O(n) is expected using hash table accumulation; avoid nested loops to prevent TLE.
How does GhostInterview help solve this problem?
GhostInterview guides you through per-creator aggregation, top video selection, and handling tie-breaking efficiently.
Solution
Solution 1: Hash Table
We traverse the three arrays, use a hash table $cnt$ to count the total play count for each creator, and use a hash table $d$ to record the index of the video with the highest play count for each creator.
class Solution:
def mostPopularCreator(
self, creators: List[str], ids: List[str], views: List[int]
) -> List[List[str]]:
cnt = defaultdict(int)
d = defaultdict(int)
for k, (c, i, v) in enumerate(zip(creators, ids, views)):
cnt[c] += v
if c not in d or views[d[c]] < v or (views[d[c]] == v and ids[d[c]] > i):
d[c] = k
mx = max(cnt.values())
return [[c, ids[d[c]]] for c, x in cnt.items() if x == mx]Continue Practicing
Continue Topic
array
Practice more edge cases under the same topic.
arrow_forwardauto_awesomeContinue Pattern
Array scanning plus hash lookup
Expand the same solving frame across more problems.
arrow_forwardsignal_cellular_altSame Difficulty Track
Medium
Stay on this level to stabilize interview delivery.
arrow_forward