Gamified challenge · Queues
pings[i] is the time in milliseconds of the i-th call to the switchboard. Times never go down, but several calls may share the same millisecond.
Write recent(pings) that returns a list with one number per ping: how many pings so far (including this one) happened in the inclusive window [t - 3000, t], where t is this ping's time.
For [1, 100, 3001, 3002] the answer is [1, 2, 3, 3]: at 3002 the window is [2, 3002], so the ping at 1 has dropped out. No pings gives [].
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google