Ctrl K

Top Channel's Best Clip

Medium
A video site hosts n clips. Clip i was made by authors[i], has id clips[i] and views[i] views. Ids are not unique: different clips may share one, yet they are still separate clips with their own view counts. An author's popularity is the total number of views across all of their clips. Find the authors with the highest popularity (there may be several) and, for each of them, their most viewed clip. If an author has several clips tied for the most views, pick the one whose id comes first alphabetically. Return a list of [author, id] pairs in any order.
Example 1
authors=["kim", "lee", "kim", "ann"], clips=["cat", "dog", "bee", "owl"], views=[4, 9, 5, 3] → [['kim', 'bee'], ['lee', 'dog']]

kim has 4 + 5 = 9 views, lee has 9, ann has 3. kim and lee share the lead. kim's best clip is bee (5 views); lee's only clip is dog.

Example 2
authors=["max", "max"], clips=["zeta", "alfa"], views=[7, 7] → [['max', 'alfa']]

Both of max's clips have 7 views, so the alphabetically smaller id, alfa, is chosen.

Example 3
authors=["sam", "tom"], clips=["a", "a"], views=[0, 1] → [['tom', 'a']]
Constraints
  • 1 ≤ n ≤ 10⁵; authors, clips and views all have length n
  • Every string in authors and clips has 1 to 10 lowercase English letters
  • 0 ≤ views[i] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMost Searched Words MediumIntern Leaderboard From Reviews MediumAnagram Buckets MediumMost Common Values MediumCharacters Grouped by Count Medium
loading Python…
Input
authors=["kim", "lee", "kim", "ann"], clips=["cat", "dog", "bee", "owl"], views=[4, 9, 5, 3]
Expected
[['kim', 'bee'], ['lee', 'dog']]

Run checks the first 3 tests in your browser. Submit checks all 96 tests on the server, hidden ones included.