Catching the Bus to the Movie
Updated
Problem statement
Bob wants to catch a movie. He will take a bus from a bus stop to the cinema.
Measure time in minutes, starting at 0. Bob reaches the stop at a uniformly random time between 0 and bobWindow. The bus reaches the stop at a uniformly random time between 0 and busWindow. The two times are independent.
The bus always stays at the stop for exactly busWait minutes and then leaves, whether or not Bob is on it. Bob gets on if he reaches the stop before the bus leaves. If he gets there first, he waits for the bus. The ride to the cinema takes rideTime minutes.
The movie starts at time movieStart. Return the probability that Bob gets on the bus and reaches the cinema no later than movieStart. Your answer is accepted if its absolute error or its relative error is at most 10^-9.
Function
onTimeProbability(bobWindow: int, busWindow: int, busWait: int, rideTime: int, movieStart: int) → doubleExamples
Example 1
bobWindow = 60busWindow = 60busWait = 10rideTime = 20movieStart = 60return = 0.20833333333333334This is the interview case: both arrive between minute 0 and minute 60, the bus waits 10 minutes, the ride takes 20, and the movie starts at minute 60.
The bus must reach the cinema by minute 60, so it must leave by minute 40. It leaves 10 minutes after it arrives, so it must arrive by minute 30.
If the bus arrives at minute u (with u at most 30), Bob gets on when he arrives by minute u + 10. On a 60 by 60 square of (Bob, bus) arrival times, these good points form a region of area 750, so the answer is 750 / 3600 = 5/24, about 0.2083.
Example 2
bobWindow = 60busWindow = 60busWait = 10rideTime = 20movieStart = 40return = 0.041666666666666664Now the movie starts at minute 40, so the bus must leave by minute 20 and arrive by minute 10.
For a bus at minute u from 0 to 10, Bob has u + 10 good minutes. The good area is 10 × 10 / 2 + 10 × 10 = 150, so the answer is 150 / 3600 = 1/24.
Example 3
bobWindow = 30busWindow = 60busWait = 0rideTime = 15movieStart = 75return = 0.75The bus does not wait at all, so Bob must be at the stop before the bus. Any bus arrival works for the movie, because 60 + 15 <= 75.
Half the time the bus comes after minute 30, and then Bob, who arrives by minute 30, is always there first. Otherwise the bus comes at minute u below 30 and Bob is first with chance u / 30, which is 1/2 on average. The answer is 1/2 + 1/2 × 1/2 = 3/4.
Constraints
1 <= bobWindow, busWindow <= 10^40 <= busWait, rideTime <= 10^40 <= movieStart <= 4 * 10^4
More Susquehanna International Group (SIG) Phone Screen questions
- Dice Sum That Is a Multiple of mPHONE SCREEN · Seen Nov 2026
- Find Median from Data StreamPHONE SCREEN · Seen Nov 2026
- Painting Arcs to Nearest Neighbors on a CirclePHONE SCREEN · Seen Sep 2026
- Filter Movies by Inclusive Year RangePHONE SCREEN · Seen Jul 2026
- Best Single Reroll for Five DicePHONE SCREEN · Seen Feb 2026
- Two Dice Summing to a TargetPHONE SCREEN · Seen Jan 2026
- Median of Uniform Draws in an IntervalPHONE SCREEN · Seen Oct 2025
- One Number Is the Average of the Other TwoPHONE SCREEN · Seen Jun 2025
- Which Coin Pattern Shows Up FirstPHONE SCREEN · Seen May 2025
- Random Points Inside One ArcPHONE SCREEN · Seen Jan 2025
Similar questions at other companies
- Range of a Third CorrelationTower Research Capital · PHONE SCREEN
- Three Points in a Semicircle: Monte Carlo EstimateSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Union Area of Two RectanglesDocuSign · PHONE SCREENDocuSign interview questions
- Intersection of Two RectanglesFigma · PHONE SCREENFigma interview questions
- Light Source Hits: Sample, Compare, and FitOpenAI · PHONE SCREENOpenAI interview questions
- Max Points on a LineUber · PHONE SCREENUber interview questions
- Count Axis-Aligned and Rotated SquaresGoogle · PHONE SCREENGoogle interview questions
- Best-Fit Plane Normal from 3D PointsThe Voleon Group · PHONE SCREEN
- Meeting of Points Moving Toward Initial SuccessorsThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Maximum Visible DronesAnduril · PHONE SCREENAnduril interview questions