#2456
Medium Algorithms Most popular video creator
Array Hash Table String Sorting Heap (Priority Queue)
45.2% acceptance
Feb 25, 2026
308
385
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. * The popularity of a creator is the sum of the number of views on all of the c
reator's videos. Find the creator with the highest popularity and the id of their most viewed video. * If multiple creators have the highest popularity, find all of them.
If multiple videos have the highest view count for a creator, find the lexico
graphically smallest id. * Note: It is possible for different videos to have the same id, meaning that i
ds do not uniquely identify a video. For example, two videos with the same ID are considered as distinct videos with their own viewcount. * Return a 2D array of strings answer where answer[i] = [creatorsi, idi] means
that creatorsi has the highest popularity and idi is the id of their most popular video. The answer can be returned in any order. *
Solution
Rust
Time O(n)
Space O(n)
impl Solution {
pub fn most_popular_creator(creators: Vec<String>, ids: Vec<String>, views: Vec<i32>) -> Vec<Vec<String>> {
use std::collections::HashMap;
let n = creators.len();
// (total_views, best_id_views, best_id)
let mut map: HashMap<&str, (i64, i32, &str)> = HashMap::new();
for i in 0..n {
let entry = map.entry(&creators[i]).or_insert((0, -1, ""));
entry.0 += views[i] as i64;
if views[i] > entry.1 || (views[i] == entry.1 && ids[i].as_str() < entry.2) {
entry.1 = views[i];
entry.2 = &ids[i];
}
}
let max_pop = map.values().map(|v| v.0).max().unwrap_or(0);
map.iter()
.filter(|(_, v)| v.0 == max_pop)
.map(|(creator, v)| vec![creator.to_string(), v.2.to_string()])
.collect()
}
}