Bus Riders After Many Stops
Updated
Problem statement
A bus starts with passengers riders and then makes stops stops. At every stop, first a fraction offNumerator / offDenominator of the riders on board get off, rounded down to a whole number of people. Then boarding new riders get on.
Return the number of riders on the bus after the last stop.
Function
passengersAfterStops(passengers: int, offNumerator: int, offDenominator: int, boarding: int, stops: int) → intExamples
Example 1
passengers = 52offNumerator = 3offDenominator = 4boarding = 7stops = 3return = 10At stop 1, 39 of the 52 riders get off and 7 get on, leaving 20. At stop 2, 15 get off and 7 get on, leaving 12. At stop 3, 9 get off and 7 get on, leaving 10.
Example 2
passengers = 100offNumerator = 1offDenominator = 2boarding = 10stops = 1000000000return = 21The count goes 100, 60, 40, 30, 25, 23, 22, 21. At 25 half is 12.5, so 12 get off. Once there are 21 riders, 10 get off and 10 get on, so the count stays at 21 for every later stop.
Example 3
passengers = 9offNumerator = 1offDenominator = 3boarding = 0stops = 2return = 4At stop 1, 3 of 9 get off, leaving 6. At stop 2, 2 get off, leaving 4. Nobody gets on.
Constraints
0 <= passengers <= 1091 <= offDenominator <= 1001 <= offNumerator <= offDenominator0 <= boarding <= 1061 <= stops <= 109
More Jane Street Phone Screen questions
- Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026
- Tree Selection and VisibilityPHONE SCREEN · Seen Nov 2026
- Load/Store Arithmetic InterpreterPHONE SCREEN · Seen Oct 2026
- Instrument Stack Language JumpsPHONE SCREEN · Seen Oct 2026
- Run a Stack Language InterpreterPHONE SCREEN · Seen Oct 2026
- Positive-Integer Expression EvaluationPHONE SCREEN · Seen Oct 2026
- Add Two Integers Given as StringsPHONE SCREEN · Seen Sep 2026
- Angle Between Clock HandsPHONE SCREEN · Seen Jul 2026
- Route Length From Two CyclistsPHONE SCREEN · Seen Jul 2026
- Sort TradesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Monthly Calendar with Custom Week StartStripe · PHONE SCREENStripe interview questions
- Fractional Share Inventory FlatteningRobinhood · PHONE SCREEN · ONSITE INTERVIEWRobinhood interview questions
- Logistic Regression DiagnosticsLinkedIn · PHONE SCREENLinkedIn interview questions
- Evenly Schedule Vehicle InspectionsAmazon · PHONE SCREEN
- Implement Cross-Entropy LossOpenAI · PHONE SCREENOpenAI interview questions
- Cumulative No-Intercept Regression BetasCitadel · PHONE SCREENCitadel interview questions
- Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
- Per-Segment SpeedingOnePay · PHONE SCREENOnePay interview questions
- Automation Pipeline, Part 2: Stage WorkersPlaid · PHONE SCREENPlaid interview questions