FastPrepVideo Advertisement Frame Ranges
Problems/Video Advertisement Frame Ranges

Video Advertisement Frame Ranges

Google logoGoogle● MediumFULLTIMEONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The Google ML report asks for frame/timestamp ranges and x,y positions of video advertisement boxes given a model. Exact rectangle matching, gap handling, dimensions, constant frame rate, timestamp rounding and ordering are explicit practice assumptions. Approximate source match: 70%.

A supplied advertisement-detection model reports rectangular boxes in video frames. Return all continuous frame and timestamp ranges occupied by each reported rectangle.

For this exercise, assume the video has frameCount frames numbered from zero and a constant integer frame rate fps. Each unordered detection row is [frame,x,y,width,height]. Identical (x,y,width,height) values identify one rectangle; repeated copies in one frame count once. Merge only consecutive frames for that exact rectangle. A missing frame splits a range; changing any coordinate or size starts a different rectangle.

Return one row [startFrame,endFrameExclusive,startMs,endMs,x,y,width,height] per maximal run. Timestamps are floor(frameBoundary * 1000 / fps) milliseconds at the respective boundaries. Sort rows lexicographically by start frame, exclusive end frame, x, y, width and height. Different rectangles remain separate even when they overlap spatially.

Function

advertisementRanges(frameCount: int, fps: int, detections: int[][]) → int[][]

Examples

Example 1

frameCount = 6fps = 10detections = [[2,0,0,2,3],[0,0,0,2,3],[1,0,0,2,3],[4,0,0,2,3]]return = [[0,3,0,300,0,0,2,3],[4,5,400,500,0,0,2,3]]

Frames zero through two form one run; the missing third frame separates frame four.

Example 2

frameCount = 3fps = 30detections = [[0,5,7,1,1],[1,0,0,2,3],[0,0,0,2,3]]return = [[0,1,0,33,5,7,1,1],[0,2,0,66,0,0,2,3]]

The shorter run comes first when start frames tie; timestamps use floored boundary times.

Example 3

frameCount = 0fps = 25detections = []return = []

No frames and no model detections produce no ranges.

Constraints

  • 0 <= frameCount <= 100000, 1 <= fps <= 1000, and 0 <= detections.length <= 10000.
  • Every detection contains five integers and 0 <= frame < frameCount. A zero-frame video has no detections.
  • 0 <= x,y <= 10000 and 1 <= width,height <= 10000.
  • All detections are accepted model outputs. There is no confidence threshold, interpolation or identity tracking across moving boxes.

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

  • Generate All Permutations of a NumberFleetx · ONSITE INTERVIEW
  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEW
  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEW
  • Group AnagramsAmazon Web Services · ONSITE INTERVIEW
  • Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEW
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEW
  • Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEW
  • Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEW
See Google hiring insights
Saved
class Solution {
    public int[][] advertisementRanges(int frameCount, int fps, int[][] detections) {
        // Write your code here
    }
}
Checking account…