Fastest lap with pit filter
EasyOnline Assessment
Find a driver's fastest "representative" lap of a race, ignoring the laps that are slowed down by the pit lane.
A timing loop logs the moment the car crosses the finish line at the end of every lap. crossings[i] is that moment, in tenths of a second since the start of the race, so lap 1 lasts crossings[0] tenths and lap i + 1 lasts crossings[i] - crossings[i - 1].
These laps do not count:
- Lap 1, which is a standing start.
- Every lap listed in
pitLaps: that lap is the one on which the car drove into the pits (the in-lap). - The lap right after each listed lap (the out-lap). Laps that do not exist are simply ignored.
Among the laps that do count, find the fastest one. If several laps share the best time, the earliest of them wins. A lap *sets a record* when it counts and is strictly faster than every counting lap before it (the first counting lap always sets a record).
Input: crossings, a strictly increasing list of integers, and pitLaps, a list of lap numbers (1-based, possibly unordered or repeated).
Output: a list [lap, duration, records] with the 1-based number of the fastest counting lap, its duration in tenths of a second, and how many records were set during the race. If no lap counts, return [].
Example 1
- Input:
- [[1052,1950,2850,3740,4650],[]]
- Output:
- [4,890,2]
- Explanation
- The laps last 1052, 898, 900, 890 and 910 tenths. Lap 1 never counts. Among laps 2 to 5 the fastest is lap 4 with 890. The record was broken on lap 2 (first eligible lap) and again on lap 4, so 2 records.
Example 2
- Input:
- [[850,1750,2630,3500,4440],[3]]
- Output:
- [2,900,1]
- Explanation
- The laps last 850, 900, 880, 870 and 940. Lap 1 is excluded even though it is the quickest. The car pitted on lap 3, so laps 3 (in-lap) and 4 (out-lap) are excluded too. Only laps 2 and 5 remain; lap 2 is faster (900) and set the only record.
Example 3
- Input:
- [[950,1830,2700,3560,4450,5340],[3,2]]
- Output:
- [5,890,1]
- Explanation
- Pit entries 3 and 2 (any order) exclude laps 2, 3 and 4, plus lap 1 as always. Laps 5 and 6 both last 890; the earlier lap wins the tie. Lap 6 did not beat the record, so only one record was set.
Constraints
0 <= crossings.length <= 500crossingsis strictly increasing, with1 <= crossings[i] <= 10,000,0000 <= pitLaps.length <= 500;1 <= pitLaps[i] <= 1,000and entries may repeat or come in any order