Analyse vehicle speed readings from a JSON feed
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Applied Intuition's technical phone screen, last asked Nov 2025. It tests json, parsing and data processing.
A URL serves a JSON document of vehicle observations recorded over time: a list of frames, each with a timestamp and the vehicles seen in that frame with their speed. Fetch the document, walk the nested observations and answer two questions: which reading is the fastest, and which vehicle's speed varied the most (largest maximum minus minimum).
Interface
Unless you agree on a different interface with the interviewer, assume:
-
load(url: str) -> dictfetches and parses the document. Raise a clear error on a failed request or invalid JSON. -
fastest_reading(doc: dict) -> tuple[str, float, float] | Nonereturns(vehicle_id, timestamp, speed)of the highest speed, orNonewhen there are no readings. -
widest_speed_range(doc: dict) -> str | Nonereturns the id of the vehicle with the largestmax(speed) - min(speed), orNonewhen there are no readings.
The document looks like this:
{"frames": [
{"timestamp": 0.0, "vehicles": [{"id": "a", "speed": 10.0}, {"id": "b", "speed": 4.0}]},
{"timestamp": 0.5, "vehicles": [{"id": "a", "speed": 12.5}, {"id": "b", "speed": 9.0}]},
{"timestamp": 1.0, "vehicles": [{"id": "a", "speed": 11.0}, {"id": "c", "speed": 3.0}]}
]}
Example
fastest_reading(doc) -> ("a", 0.5, 12.5)
widest_speed_range(doc) -> "b" # a spans 10.0..12.5 = 2.5, b spans 4.0..9.0 = 5.0, c spans 0
Constraints
- A vehicle may be missing from some frames, and frames may hold any number of vehicles.
- Decide and state a tie rule (for example, the earliest reading or the smallest id wins).
Clarifying questions
- What is the exact JSON shape, and can fields be missing or carry the wrong type?
- Which units are the speeds in, and are they all the same?
- How should ties be broken for either answer?
- Does a vehicle seen only once count for the range question (its range is 0)?
- Is the document small enough to load whole, or should it be streamed?
What a strong answer covers
- One pass over the frames that keeps the best reading and a running min and max per vehicle: O(readings) time, O(vehicles) memory.
- Defensive parsing: missing keys, empty frames, an empty document, network and JSON errors handled with clear messages.
- Small hand-checked test documents for the empty case, a single reading, ties and a vehicle that appears in only some frames.
Follow-ups
- Some readings have
"speed": null. Skip them without breaking either answer, and say what to return for a vehicle with no valid readings. - Negative speeds are now legitimate (a vehicle reversing). Keep them in the range, and say whether "fastest" means the highest value or the largest magnitude.
- The document no longer fits in memory: stream it and keep the same answers.
Where it's asked
- Applied Intuition · Technical phone screen · Last asked Nov 202545 min · Live coding in CoderPad; the language can be fixed by the role (Python, C++, or C for embedded)
What it tests
json · parsing · data processing
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
