All problems

Kiln readings appear out of order after the ring buffer wraps

Level 2 · node · Correctness · Logical read start in a ring buffer

Scenario

A fictional pottery kiln monitor retains only the most recent readings in limited memory. Once storage is full, new readings overwrite the oldest ones. The dashboard must show retained readings in chronological order, but their order becomes mixed up after the write position wraps to the start.

Requirements

Return the retained readings for each kiln from oldest to newest. Exclude readings displaced by the capacity limit and return an empty array when there are no readings. Reading the history must not change stored state.

Acceptance criteria

  • Return readings in insertion order when fewer than capacity have been stored.
  • After the write position wraps, return only the latest retained readings in chronological order.
  • Return all readings in order when exactly capacity readings have been stored.
  • Return an empty array for no readings and identical results on repeated reads.