Short systems utility tasks: spikes, logs and brackets
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Nvidia's coding round, last asked Feb 2026. It tests arrays, parsing and stacks.
Three short utility problems of the kind a systems team writes every week. Solve each with clean code, the right data structure and its complexity.
Part 1: temperature spike
You get CPU temperature readings as (timestamp_seconds, celsius) pairs, sorted by time. A spike is a reading that is more than rise degrees above the lowest reading in the previous window seconds (readings with timestamp at least t - window). Return the timestamp of the first spike, or None.
first_spike(readings: list[tuple[int, float]], window: int, rise: float) -> int | None
first_spike([(0, 50), (10, 52), (20, 51), (30, 63), (40, 70)], 20, 10) -> 30
# at t=30 the lowest reading since t=10 is 51, and 63 - 51 = 12 > 10
first_spike([(0, 50), (30, 58), (60, 66)], 20, 10) -> None
# each earlier reading is more than 20 s back
Part 2: balanced brackets
Return whether every (, [ and { in an expression is closed by the matching bracket in the right order. Other characters are ignored.
is_balanced(expr: str) -> bool
is_balanced("f(a[i]) + {b}") -> True
is_balanced("([)]") -> False
is_balanced("((") -> False
Part 3: aggregate log lines
Each line is METHOD PATH STATUS LATENCY_MS. Return, for each status code, the number of requests and the average latency.
summarize(lines: list[str]) -> dict[str, tuple[int, float]]
["GET /a 200 120", "GET /b 500 300", "POST /a 200 80",
"GET /c 404 15", "GET /a 500 100"]
-> {"200": (2, 100.0), "404": (1, 15.0), "500": (2, 200.0)}
Constraints
- Up to 10^6 readings or lines; each part should be O(n).
- Unless the interviewer says otherwise, skip malformed log lines and count them.
Clarifying questions
- Part 1: is the window inclusive at its start? Is a spike measured against the lowest reading or against the previous one?
- Part 2: can brackets appear inside string literals that should be ignored?
- Part 3: should the averages be exact, or are percentiles (p50, p99) wanted too?
- Part 3: does the log fit in memory, or should it be streamed?
What a strong answer covers
- Part 1: a monotonic deque holding candidate minimums, popping old readings from the front and larger ones from the back, for O(1) amortized per reading.
- Part 2: a stack and a map from closing to opening bracket; failing early on a mismatch and checking the stack is empty at the end.
- Part 3: a single streaming pass with a running count and sum per status; parsing defensively.
- Tests for each part, including empty input and boundaries such as a reading exactly
windowseconds back.
Follow-ups
- Part 1: report every spike, but only once per episode until the temperature falls back.
- Part 3: add p99 latency per status for a log too large for memory.
- Part 3: aggregate logs from 1,000 machines.
Where it's asked
- Nvidia · Coding · Last asked Feb 2026Live coding, often C++-leaning; each round usually opens with 10 to 15 minutes on your past work · Assume no AI unless the interviewer offers it
What it tests
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.
