FastPrepRepeated Titles in Viewing History

Repeated Titles in Viewing History

Netflix logoNetflix● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Analyze a viewing history and report titles that were watched more than once.

Return one row [title, count] for every repeated title. Order rows by count from highest to lowest. Titles with the same count retain the order of their first appearance in the history. This ordering must be produced with frequency buckets rather than comparison-sorting the result.

Function

repeatedViewingTitles(history: String[]) → String[][]

Examples

Example 1

history = ["A","B","A","C","B","A"]return = [["A","3"],["B","2"]]

A has the highest repeat count, followed by B.

Example 2

history = ["D","C","C","D","E","E"]return = [["D","2"],["C","2"],["E","2"]]

All counts tie, so first-appearance order decides.

Example 3

history = ["only","once"]return = []

No title repeats.

Constraints

  • 0 <= history.length <= 1000000.
  • Every title is a non-empty case-sensitive string of length at most 200.

More Netflix problems

See Netflix hiring insights
public String[][] repeatedViewingTitles(String[] history) {
    // Write your solution here.
}
history["A","B","A","C","B","A"]
expected[["A", "3"], ["B", "2"]]
Checking account…