Most Popular Video Creator — LeetCode 2456 Python Solution
- Problem
- #2456
- Pattern
- Heap / Priority Queue
- Reading time
- 2 min
- Source
- leetcode.com
The problem
You are given two string arrays creators and ids, and an integer array views, all of length n. The ith video on a platform was created by creators[i], has an id of ids[i], and has views[i] views.
Python solution
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]Complexity
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(n) auxiliary |
Pattern: Heap / Priority Queue
Keep only the best k elements, or always pull the smallest, in log time. LeetCode 2456. Most Popular Video Creator is filed here because LeetCode tags it Heap (Priority Queue), which is the vocabulary this hub collects.
The heap / priority queue guide has the Python template for the pattern and the 163 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 2456. Most Popular Video Creator?
- LeetCode 2456. Most Popular Video Creator is rated Medium on LeetCode.
- What is the time complexity of LeetCode 2456. Most Popular Video Creator?
- The Python solution on this page runs in O(n).
- What is the space complexity of LeetCode 2456. Most Popular Video Creator?
- The Python solution on this page uses O(n) auxiliary space.
- What topics does LeetCode 2456. Most Popular Video Creator cover?
- LeetCode 2456. Most Popular Video Creator is tagged Array, Hash Table, String, Sorting and Heap (Priority Queue) on LeetCode.