FastPrepTop K Videos by Multiplicative Similarity
Problems/Top K Videos by Multiplicative Similarity

Top K Videos by Multiplicative Similarity

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Google AI/ML onsite report asks for the K most similar videos when similarity along two links multiplies. The author used a graph and a greedy approach, with an RPC follow-up for remote nodes. The report did not give the graph direction, the edge weights, how paths are scored, a tie rule, input limits, or a runnable interface. We state those assumptions. Getting remote nodes stays an interview discussion and is not part of the function we check.

A video catalog contains n videos labeled 0 through n - 1. Each row [u, v, w] of edges means videos u and v have direct similarity w in both directions.

The similarity of a path is the product of its edge weights. For each video reachable from source, use the maximum product over all paths from source to that video. Return up to k reachable video IDs other than source, ordered by decreasing maximum similarity. Break equal-score ties by smaller video ID. If fewer than k other videos are reachable, return all of them.

All graph edges are available locally for this coding exercise. A discussion follow-up asks how to fetch a node that is not stored locally; an RPC-backed neighbor lookup is not a graded input.

Function

topKSimilarVideos(n: int, edges: double[][], source: int, k: int) → int[]

Examples

Example 1

n = 5edges = [[0,1,0.5],[1,2,0.5],[0,3,0.25],[3,4,1.0]]source = 0k = 3return = [1, 2, 3]

Video 1 scores 0.5. Videos 2, 3, and 4 each score 0.25, so the smaller IDs 2 and 3 fill the remaining slots.

Example 2

n = 3edges = [[0,1,0.25],[0,2,0.5],[2,1,1.0]]source = 0k = 2return = [1, 2]

The indirect route to video 1 scores 0.5, improving its direct 0.25 link. It ties video 2 and wins by ID.

Example 3

n = 4edges = [[0,1,0.5]]source = 0k = 3return = [1]

Only video 1 is reachable from video 0, so the result contains fewer than three IDs.

Example 4

n = 2edges = [[0,1,1.0]]source = 0k = 0return = []

Requesting zero recommendations returns an empty array.

Constraints

  • 2 <= n <= 200; 0 <= edges.length <= n * (n - 1) / 2.
  • Each edge has two distinct valid video IDs, and no unordered pair occurs twice.
  • Each edge weight is exactly 0.25, 0.5, or 1.0.
  • 0 <= source < 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

  • Maximum K-Star SumAkuna Capital · OAAkuna Capital interview questions
  • Mutual-Friend Referral RecommendationsFireworks AI · PHONE SCREEN · ONSITE INTERVIEW
  • Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEWGusto interview questions
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
  • Minimum Railway PlatformsMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
  • Reduce Array Size to At Most HalfMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Top-Down Employee Reporting ForestOkta · ONSITE INTERVIEWOkta interview questions
  • Maximize Monsters DefeatedSalesforce · ONSITE INTERVIEWSalesforce interview questions

Interview reports that mention this question

  • Google PhD NLP New Grad Onsite: 1 Experience

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[] topKSimilarVideos(int n, double[][] edges, int source, int k) {
        // Write your code here.
    }
}
Checking account…