Average Speed Over Laps
Updated
Problem statement
A car drives several laps, one after another. Lap i is lapLengths[i] miles long, and the car drives the whole lap at a constant speeds[i] miles per hour.
Return the car's average speed over the whole drive, in miles per hour: the total distance divided by the total time.
Answers within 10-6 of the correct value are accepted.
Function
averageSpeed(lapLengths: int[], speeds: int[]) → doubleExamples
Example 1
lapLengths = [1,1]speeds = [60,90]return = 72.0Lap 1 takes 1/60 of an hour and lap 2 takes 1/90 of an hour, 1/36 of an hour in total. Two miles in 1/36 of an hour is 72 miles per hour. It is not 75, because the car spends more time on the slower lap.
Example 2
lapLengths = [30,60]speeds = [30,60]return = 45.0Both laps take one hour, so the car spends equal time at each speed. Total distance 90 miles over 2 hours gives 45, which here happens to be the plain average of the two speeds.
Example 3
lapLengths = [5]speeds = [40]return = 40.0With one lap the average speed is that lap's speed.
Constraints
1 <= lapLengths.length <= 104speeds.length == lapLengths.length1 <= lapLengths[i] <= 10001 <= speeds[i] <= 1000
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
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Length of a Document Reached Through a Random TokenMercor · PHONE SCREENMercor interview questions
- Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
- Exponential Backoff DelaysWonderful · PHONE SCREEN
- One-Nearest-Neighbor Classification with Manhattan DistanceOpenAI · PHONE SCREENOpenAI interview questions
- Recover Document Hierarchy from IndentationReducto · PHONE SCREEN
- Average Grades per StudentHartford Financial Services · PHONE SCREENHartford Financial Services interview questions
- Through-Origin Linear RegressionMeta · PHONE SCREENMeta interview questions
- Latency Bucket CounterDatadog · OA · PHONE SCREENDatadog interview questions
Interview reports that mention this question
Jane Street interview experiences
- Jane Street TDO UK and Hong Kong: 22 Experiences (Part 10 of 10)
- Jane Street TDOE US Final Round: 11 Experiences (Part 5 of 10)
- Jane Street TDO Phone Math Round: 26 Experiences (Part 9 of 10)
- Jane Street TDOE UK Phone Screen: 15 Experiences (Part 4 of 10)
- Jane Street TDO Excel and VBA Test: 23 Experiences (Part 8 of 10)