FastPrepTop-Rated Similar Movies
Problems/Top-Rated Similar Movies

Top-Rated Similar Movies

Google logoGoogle● MediumINTERNFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for the "Highest-rated movie" and then top K.

The report gives title ordering for ties. Here, movies use numeric IDs, and tied ratings use the smaller ID. The editorial explains how title-ordered IDs encode that variant. Edges are directed, all reachable movies except the starting movie are eligible, and we supply the limits.

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

There are n movies with IDs 0 through n - 1. Movie i has rating ratings[i] and a list similar[i] of movie IDs. Given a starting movie start and an integer k, return the IDs of the highest-rated eligible movies.

Recommendation rules

  • The lists describe a directed graph: an entry v in similar[u] allows traversal from u to v. It does not imply a reverse edge.
  • A movie is eligible if it is reachable from start by following one or more listed edges, including paths through other movies. The starting movie itself is always excluded, even if a cycle reaches it again.
  • Lists may contain duplicate entries and self-edges. Each eligible movie appears at most once in the answer.
  • Rank eligible movies by rating in descending order. When ratings tie, the smaller movie ID comes first.
  • Return the first min(k, number of eligible movies) IDs in that order. Return an empty array when k = 0 or no movie is eligible.

Ratings belong to movies. Edges have no numerical scores, and path length does not affect ranking. A high-rated movie may be reachable only through low-rated movies, so those intermediate movies still need to be explored.

Function

topRatedSimilarMovies(ratings: int[], similar: int[][], start: int, k: int) → int[]

Examples

Example 1

ratings = [60,80,95,95,100]similar = [[1,2],[3],[],[],[]]start = 0k = 2return = [2,3]

Movies 1, 2, 3 are reachable. Movies 2 and 3 tie at rating 95, so their IDs appear in ascending order. Movie 4 is unreachable despite its higher rating.

Example 2

ratings = [100,20,90,100]similar = [[1],[0,2],[],[]]start = 0k = 4return = [2,1]

Only movies 1 and 2 are eligible. The cycle back to movie 0 does not make the starting movie a recommendation, and movie 3 is unreachable.

Example 3

ratings = [7,9]similar = [[1],[0]]start = 0k = 0return = []

No recommendations are requested when k = 0.

Constraints

  • 1 <= n <= 1500 and ratings.length = similar.length = n.
  • 0 <= ratings[i] <= 10^9.
  • The total number of entries across all adjacency lists is at most 3000, counting duplicates and self-edges.
  • Every listed movie ID is in [0, n - 1].
  • 0 <= start < n and 0 <= k <= n.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Aggregate Machine TopologyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Deterministic Depth-First Graph TraversalWaymo · PHONE SCREENWaymo interview questions
  • Traverse an Up-Down-Right Pointer StructureBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Reconstruct ItineraryTripjack · ONSITE INTERVIEWTripjack interview questions
  • Module Rebuild CostsAirbnb · OAAirbnb interview questions
  • Priority Graph: First Arrival TimesIntuit · OAIntuit interview questions
  • Evolving Merchant Clusters and Persistent PinsStripe · OAStripe interview questions
  • Create Lexicographically Largest PermutationOracle · OAOracle interview questions
  • Topological OrderingApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions

Interview reports that mention this question

  • Google SWE III ML Interviews: 11 Experiences (Part 1 of 3)

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[] topRatedSimilarMovies(int[] ratings, int[][] similar, int start, int k) {
        // write your code here
    }
}
Checking account…