Schedule Buffered Video Playback
Updated
Problem statement
A video contains one ordered frame per entry in readDurations. Reading begins at time 0. Frame i takes readDurations[i] milliseconds to read, and the next read begins immediately after the previous one finishes.
Playback must render every frame in order at exactly 25 frames per second. Therefore, if playback starts at time start, frame i is rendered at time start + 40 * i. A frame may be rendered exactly when its read finishes, but never before it is ready.
Use one sequential reader and one sequential renderer: read calls never overlap other read calls, render calls never overlap other render calls, and the read and render sequences may overlap each other.
Choose the earliest nonnegative playback start that prevents buffer underflow for every frame. Return an array containing the render timestamp of each frame.
Function
scheduleVideoFrames(readDurations: long[]) → long[]Examples
Example 1
readDurations = [10,10,10]return = [10,50,90]The frames become ready at times 10, 20, and 30. Starting playback at time 10 is sufficient, so the render calls occur at 10, 50, and 90.
Example 2
readDurations = [70,70,10]return = [100,140,180]The first two frames become ready at times 70 and 140. A start before 100 would request the second frame before it is ready. Starting at 100 is the earliest underflow-free choice.
Example 3
readDurations = [0,100,0]return = [60,100,140]The second frame is not ready until time 100. A playback start of 60 schedules that frame at time 100 while retaining the exact 40-millisecond cadence.
Constraints
1 <= readDurations.length <= 100000.0 <= readDurations[i] <= 10^9.- Every cumulative read time and render timestamp fits in a signed 64-bit integer.
More Nuro interview questions
- Merge Timestamped Record ListsPHONE SCREEN · Seen Oct 2026
- Assign Robots to Their Nearest Available ItemsPHONE SCREEN · Seen Oct 2026
- Container With Most WaterPHONE SCREEN · Seen Oct 2026
- Course Ordering with Concurrent UpdatesPHONE SCREEN · Seen Sep 2026
- Group Sparse Points by Distance ThresholdPHONE SCREEN · Seen Sep 2026
- Reveal a Minesweeper RegionPHONE SCREEN · Seen Aug 2026
- Maximum Value for Two Delivery RobotsPHONE SCREEN · Seen Jul 2026
- Thread-Safe Task Storage and Worker DispatchONSITE INTERVIEW · Seen Sep 2026
- Trapping Rain WaterONSITE INTERVIEW · Seen Sep 2026
- Versioned Key-Value Store with Suffix TruncationONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Instrument Stack Language JumpsJane Street · PHONE SCREENJane Street interview questions
- Concurrent Discounted Card PurchasesBrex · PHONE SCREEN
- Simulate a Queued Multi-Rule Rate LimiterSnowflake · PHONE SCREENSnowflake interview questions
- First Successful Concurrent API Result Before a TimeoutApple · PHONE SCREENApple interview questions
- Wallet Balance on a Selected DayBharatPe · PHONE SCREEN
- Calculate Server Shutdown PenaltyStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Shared Counter Snapshot SumTesla · ONSITE INTERVIEWTesla interview questions
- Circuit Breaker State MachineWise · ONSITE INTERVIEW
- Hall of Shifting TilesAdobe · OAAdobe interview questions
- Weighted Lottery WinnersAmazon · ONSITE INTERVIEW