As reported: Disney SDE 2 interview (2026), round 2 (virtual): design a method that takes a genre, calls an API returning movie titles with their ratings for that genre, and returns the top-rated movie; on a tie return the lexicographically smallest title. The API is paginated by a page-number query parameter, so every page must be fetched.
You are given a client for a movie API. api.fetchPage(genre, page) returns one page of results for a genre (pages are numbered from 1):
Page {
page: int // the page that was returned
totalPages: int // how many pages this genre has (0 if the genre has no movies)
data: Movie[] // the movies on this page
}
Movie { title: string, rating: number }
Implement topRatedMovie(genre, api): fetch all pages for the genre and return the title with the highest rating. If several movies share the highest rating, return the lexicographically smallest title (plain character-code order). If the genre has no movies, return "".
Example 1
genre = "Action"
page 1: totalPages = 2, data = [("Die Hard", 8.2), ("Mad Max: Fury Road", 8.1)]
page 2: totalPages = 2, data = [("Heat", 8.3), ("Gladiator", 8.5)]
Output: "Gladiator"
Example 2
genre = "Comedy"
page 1: totalPages = 1, data = [("Superbad", 7.6), ("Groundhog Day", 8.0), ("Airplane!", 8.0)]
Output: "Airplane!"
"Airplane!" and "Groundhog Day" tie at 8.0; "Airplane!" is smaller.
Constraints: at most 1000 pages per genre and 100 movies per page; ratings are between 0 and 10 with one decimal; titles are non-empty ASCII strings and may repeat across pages. Each call to fetchPage stands for an HTTP request, so request each page once.
Code runner format: three JSON lines: genre; the list of genres the API knows; for each known genre, its pages as lists of [title, rating] pairs. The runner builds api from them. Implement topRatedMovie(genre, api).