Signals

Heartbeat gaps, with a bug

Find gaps in scheduled heartbeat timestamps so an operator can inspect missing telemetry.

In production

Missed heartbeats are the difference between a quiet host and a missing one. Inventing or dropping times hides outages.

What it must return

Return the expected heartbeat timestamps in [start, end] that never appear in the received set.

  • start <= end; interval > 0; all values are integer seconds. Return missing scheduled times start, start+interval, ... <= end. Duplicate or off-schedule timestamps do not create extra slots.
  • Do not mutate input values. Use the Python standard library only.

Edge cases

  • Generate the schedule from start, end, and interval; do not infer it only from observations.
  • Membership checks belong on a set of received timestamps.
  • Do not mutate the input list.

Signature

heartbeat_gaps(timestamps, start, end, interval)

This version runs but gets some cases wrong. Run the examples first to see which case fails.

Hints

  1. Second hint

  2. A partial sketch

The reference solution opens after the last hint.

solution.py · Python

Loading editor…

Missing slots

timestamps

[
  0,
  20,
  20,
  31
]

start

0

end

40

interval

10

Expected

[
  10,
  30,
  40
]

Each run uses a fresh Python runtime in this browser, with a 3-second limit and a Stop button. The first run downloads the runtime. 0 of 12 in Signals passed in Python on this device.

Next: Configuration drift