FastPrepBest TV Show in a Genre
Problem · Array

Best TV Show in a Genre

Learn this problem
MediumAdyen logoAdyenFULLTIMEOA

Problem statement

A paginated TV-series service has already been fetched for you. The outer index of each matrix is a page in increasing page-number order. For every page and record index, namesByPage[page][i], genresByPage[page][i], and ratingsByPage[page][i] describe the same show.

Each genre string is a comma-separated list. A show matches genre when one trimmed genre token equals the requested genre ignoring letter case. Ratings are represented as integer tenths, so 93 means 9.3.

Return the matching show's name with the highest rating across all pages. If several matching shows have the same highest rating, return the lexicographically smallest name.

Function

bestShowInGenre(genre: String, namesByPage: String[][], genresByPage: String[][], ratingsByPage: int[][]) → String

Examples

Example 1

genre = "Action"namesByPage = [["Game of Thrones","Breaking Bad"],["Band of Brothers"]]genresByPage = [["Action, Adventure, Drama","Crime, Drama, Thriller"],["Action, Drama, History"]]ratingsByPage = [[93,95],[92]]return = "Game of Thrones"

Two shows match Action. Game of Thrones has the higher rating, so it is returned even though another page is scanned later.

Example 2

genre = "Animation"namesByPage = [["Rick and Morty"],["Avatar: The Last Airbender"]]genresByPage = [["Animation, Adventure, Comedy"],["Animation, Action, Adventure"]]ratingsByPage = [[92],[92]]return = "Avatar: The Last Airbender"

The two matching shows tie at 9.2, so the lexicographically smaller name is returned.

Example 3

genre = "drama"namesByPage = [["North","South"],["East","West"]]genresByPage = [["Drama","Comedy"],["Crime, DRAMA","Drama, Mystery"]]ratingsByPage = [[80,99],[91,88]]return = "East"

Genre matching ignores case but compares complete comma-delimited tokens. East has the highest matching rating.

Constraints

  • 1 <= namesByPage.length == genresByPage.length == ratingsByPage.length <= 8
  • All three rows on a page have equal length, and each page contains at most 32 records.
  • The snapshot contains between 1 and 256 records in total.
  • 1 <= genre.length <= 40, and the requested genre has no leading or trailing whitespace.
  • 1 <= namesByPage[page][i].length <= 100
  • 0 <= ratingsByPage[page][i] <= 100; a value is the IMDB rating multiplied by ten.
  • At least one record contains a genre token matching genre.

More Adyen problems

drafts saved locally
public String bestShowInGenre(String genre, String[][] namesByPage, String[][] genresByPage, int[][] ratingsByPage) {
    // write your code here
}
genre"Action"
namesByPage[["Game of Thrones","Breaking Bad"],["Band of Brothers"]]
genresByPage[["Action, Adventure, Drama","Crime, Drama, Thriller"],["Action, Drama, History"]]
ratingsByPage[[93,95],[92]]
expected"Game of Thrones"
checking account