β back to unit
Easy
# queues easy
The Last Five Readings
The weather display only shows the freshest k readings β old ones fall off the back as new ones arrive. π‘οΈ
You get the readings in arrival order and the display size k. Feed them through a deque that never grows past k (drop the oldest when full). Print the final display, oldest first, comma-separated.
Example:
Input: readings = [3, 8, 2, 9, 4, 7], k = 3
Output: 9,4,7
Each new reading is appended, and once the deque holds more than 3 the oldest one is dropped. After all six readings arrive, only the freshest three remain: 9, 4, 7.
π‘ need a hint?
q-last-five-readings.pyπ given lines are locked β write your code in between
loading...