You are given a sequence of like events. The i-th event contributes likeCounts[i] likes to creator kolIds[i].
Aggregate total likes per creator, then return the top k creators sorted by total likes descending. Break ties by creator ID ascending.
Return each ranked result as a single string formatted "creator totalLikes".
Complete the function topKKolsByLikes in the editor below.
topKKolsByLikes has the following parameters:
String[] kolIds: creator identifiersint[] likeCounts: likes contributed by each eventint k: the number of creators to return
Returns
String[]: the top k ranked creator totals.
Examples
01 · Example 1
kolIds = ["A", "B", "A", "C", "B", "D"] likeCounts = [1, 5, 3, 2, 1, 10] k = 2 return = ["D 10", "B 6"]
D has the highest total likes, followed by B.
02 · Example 2
kolIds = ["ann", "bob", "ann", "bob"] likeCounts = [2, 1, 1, 2] k = 2 return = ["ann 3", "bob 3"]
Both creators tie at 3 total likes, so ID order breaks the tie.
Constraints
1 <= kolIds.length == likeCounts.length <= 2 * 10^51 <= k <=the number of distinct creators0 <= likeCounts[i] <= 10^9
More Tiktok problems
- LRU Cache with TTL ExpirationONSITE INTERVIEW · Seen May 2026
- Maximum Candies with At Most Two Types in a LineONSITE INTERVIEW · Seen May 2026
- Compute Walking DistanceSeen Mar 2026
- Count Sawtooth SubarraysSeen Mar 2026
- Format TextSeen Mar 2026
- Memory AllocatorSeen Mar 2026
- TikTok Shopping SpreeSeen Mar 2025
- TikTok Video Relevance AdjustmentSeen Mar 2025
public String[] topKKolsByLikes(String[] kolIds, int[] likeCounts, int k) {
// write your code here
}
kolIds["A", "B", "A", "C", "B", "D"]
likeCounts[1, 5, 3, 2, 1, 10]
k2
expected["D 10", "B 6"]
sign in to submit