Sustained Overspeed Alerts
Updated
Problem statement
A fleet tracker receives GPS pings from many vehicles. Each vehicle is meant to send one ping every 10 seconds, but a ping can be lost. Each ping is pings[i] = [vehicleId, timestamp, speed]: the id of the vehicle, the time in seconds, and the vehicle's speed in km/h. The pings are given in time order across all vehicles.
A ping is fast when its speed is greater than 90. A speed of exactly 90 is not fast. A run is a sequence of fast pings from one vehicle in which each ping comes exactly 10 seconds after the one before it. A run ends when the vehicle sends a ping that is not fast, or when its next ping comes more than 10 seconds after its previous one (the pings in between were lost). A fast ping that does not continue a run starts a new one.
A vehicle has been over 90 km/h continuously for 2 minutes when its run reaches a ping 120 seconds after the run's first ping, which is the 13th ping of the run. Raise an alert [vehicleId, timestamp] at that ping. A run raises at most one alert: later pings of the same run raise nothing, and the vehicle must start a new run and keep it for another 2 minutes to raise another alert.
Return all alerts in the order their pings appear in pings. If there are none, return an empty list.
Function
findOverspeedAlerts(pings: int[][]) → List<List<Integer>>Examples
Example 1
pings = [[1,0,91],[1,10,93],[1,20,96],[1,30,99],[1,40,102],[1,50,104],[1,60,103],[1,70,101],[1,80,98],[1,90,95],[1,100,94],[1,110,92],[1,120,97],[1,130,100]]return = [[1,120]]Vehicle 1 is above 90 on every ping. The pings at times 0 to 120 form a run of 13 pings, and the 13th ping is 120 seconds after the first, so the alert is raised at time 120. The ping at 130 belongs to the same run, so it raises nothing. A speed of 91 already counts as fast.
Example 2
pings = [[9,0,110],[4,0,92],[9,10,108],[4,10,95],[9,20,105],[4,20,97],[9,30,100],[4,30,100],[9,40,97],[4,40,101],[9,50,94],[4,50,99],[9,60,90],[4,60,96],[9,70,96],[4,70,94],[9,80,99],[4,80,93],[9,90,103],[4,90,95],[9,100,107],[4,100,98],[9,110,111],[4,110,102],[9,120,115],[4,120,104]]return = [[4,120]]Both vehicles send a ping every 10 seconds from time 0 to 120. All 13 of vehicle 4's pings are above 90, so at time 120 its run is 13 pings long, spans 120 seconds, and raises an alert. Vehicle 9 reports exactly 90 at time 60, which is not fast, so its run ends there. Its new run starts at time 70 and has only 6 pings by time 120.
Example 3
pings = [[6,0,120],[6,10,120],[6,20,120],[6,30,120],[6,40,120],[6,50,120],[6,60,120],[6,80,120],[6,90,120],[6,100,120],[6,110,120],[6,120,120],[6,130,120]]return = []Vehicle 6 is at 120 on all 13 pings, but there is no ping at time 70. The ping at 80 comes 20 seconds after the one at 60, so the first run ends with 7 pings and a new run starts. The new run has 6 pings, from 80 to 130, so no run lasts 2 minutes.
Constraints
1 <= pings.length <= 10^4pings[i].length == 31 <= vehicleId <= 10^90 <= timestamp <= 10^9timestampis a multiple of100 <= speed <= 300pings[i][1] <= pings[i + 1][1]- No vehicle has two pings with the same
timestamp.
More Fleetx Onsite Interview questions
Similar questions at other companies
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Deep Copy a Random-Pointer ListAmazon · ONSITE INTERVIEW
- Instant-Runoff Voting WinnerWise · ONSITE INTERVIEW
- Escape Room LeaderboardPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
- Random Picks Excluding Recent ValuesGoogle · ONSITE INTERVIEWGoogle interview questions
- Minimum Days for Fixed-Order Tasks with CooldownCoinbase · ONSITE INTERVIEWCoinbase interview questions
- Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions
- Read a File from Distributed ChunksHudson River Trading · ONSITE INTERVIEWHudson River Trading interview questions