FastPrepTop K Movies by Play Count from CSV Data
Problems/Top K Movies by Play Count from CSV Data

Top K Movies by Play Count from CSV Data

Tubi logoTubi● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This comes from a staff-level Tubi phone screen. The coding round was about ranking movie records that sit in a CSV file behind a URL, picking the k most played. By the candidate's account the ranking itself was easy, and the real work was production-style code around it: fetching the file, and parsing fields that are not quoted the same way everywhere.

The report lists the kinds of fields only loosely and gives no exact header, sample data, tie rule or limits. Here, the fetched response is already given to you as an array of lines, the first being the header title,author,play_count,duration. Fields follow the common CSV quoting rules, and a quoted play count may use commas as thousands separators. The answer is the titles, best first. Ties go to the smaller title, all movies are returned when there are fewer than k, and the limits and examples are ours.

Our version is about 70% the same as the reported question.

A movie service returns its catalog as CSV data. The response has already been fetched and split into lines for you: lines[0] is the header title,author,play_count,duration, and every other line describes one movie with those four fields, separated by commas.

The data is not written consistently, so each field must be decoded:

  • A field may be written as-is. It then contains no comma and no double quote.
  • A field may instead be wrapped in double quotes. Inside the quotes a comma is an ordinary character, and each double quote in the value is written twice (""). The outer quotes are not part of the value.
  • A quoted play_count may use commas as thousands separators, such as "1,234,567". Without quotes it is plain digits.

Return the titles of the k movies with the most plays, the most played first. When two movies have the same play count, the one whose title is smaller in string order (comparing character codes, so uppercase letters come before lowercase) comes first. If there are fewer than k movies, return all of them in that order.

Function

topKMovies(lines: String[], k: int) → String[]

Examples

Example 1

lines = ["title,author,play_count,duration","Night Train,Ana Ruiz,5200,95","\"Hello, World\",Bo Chen,\"12,000\",88","Big Day,Cy Diaz,800,102","\"The \"\"Last\"\" Stop\",Di Evans,5200,77"]k = 2return = ["Hello, World","Night Train"]
  • "Hello, World" is quoted because the title has a comma. Its play count "12,000" is quoted too and means 12000, the most plays.
  • Night Train and The "Last" Stop both have 5200 plays. Inside quotes, "" stands for one ", so the second title is The "Last" Stop.
  • The tie goes to the smaller title in string order, and "N" comes before "T", so Night Train is second.

Example 2

lines = ["title,author,play_count,duration","Alpha,Ann Lee,10,60","\"Beta\",Ann Lee,\"7\",61"]k = 5return = ["Alpha","Beta"]

There are only two movies, so both are returned even though k = 5. The quotes around Beta and 7 are not part of the values.

Example 3

lines = ["title,author,play_count,duration"]k = 1return = []

The data has only the header line and no movies, so the answer is empty.

Constraints

  • 1 <= lines.length <= 301
  • 1 <= k <= 300
  • lines[0] is exactly "title,author,play_count,duration".
  • Every other line has exactly four fields in the format described above. A title has 1 to 30 characters and an author 1 to 20, using English letters, digits, spaces and the characters . ' ! & : ( ) - , ". An unquoted field never contains a comma or a double quote, and no value starts or ends with a space.
  • Each play_count is a whole number from 0 to 10^9 without leading zeros. Each duration is a whole number from 1 to 600, quoted or not, without separators.
  • All titles are different.

More Tubi Phone Screen questions

  • Video Cache Hit Rates from a CSV LogPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Top N Frequent Words in a FileMeta · PHONE SCREENMeta interview questions
  • Time-Aware Search AutocompleteRoblox · PHONE SCREENRoblox interview questions
  • Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
  • Stable Top K Frequent WordsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Brazilian Receivables Part 3 — Partial ContractsStripe · PHONE SCREENStripe interview questions
  • Sort Characters by How Often They AppearAdobe · PHONE SCREENAdobe interview questions
  • Top Counted Word RecordsIndeed · PHONE SCREENIndeed interview questions
  • Summarize Server Healthcheck LogsNVIDIA · PHONE SCREENNVIDIA interview questions
  • Find Valid IP AddressesVerkada · PHONE SCREENVerkada interview questions
  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
See Tubi hiring insights
Saved
class Solution {
    public String[] topKMovies(String[] lines, int k) {
        // Write your code here.
    }
}
Checking account…