Code RoomDivision by zero on empty input
MediumPrep Room Coding #1900

Division by zero on empty input

Code reviewCode quality & reviewMid–Senior~15 min

Review this Python code that summarizes latency once per scrape interval.

`scrape` runs on a fixed timer regardless of whether any traffic arrived in the window.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 15 min
Mark a line and say what kind of problem it is.0 findings
1def avg_latency(samples):
2 total = 0
3 for s in samples:
4 total += s.latency_ms
5 return total / len(samples)
6 
7def scrape(window):
8 samples = collect(window) # whatever arrived this interval
9 avg = avg_latency(samples)
10 emit_gauge("latency.avg_ms", avg)
11 return avg
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.