Question bank › Queue
Dsa Queue Easy

Sensor Spike Filter

A sensor stream provides integers. We maintain a sliding window of the last W *valid* readings to calculate a 'running average'. A new reading is considered 'valid' if it is within T units (inclusive) of the current window's average. If valid, it is added to the window (and the oldest is removed if the window size exceeds W). If invalid, it is a 'spike' and is ignored. Input: W (window size), T (threshold), and then a series of integers until EOF. Note: For the very first reading, the average is considered to be the reading itself (it is always valid). Output: For each reading, print 'OK' if it's valid or 'SPIKE' if it's ignored. Example: Input: 3 10 20 25 50 22 Output: OK OK SPIKE OK

Key concepts

queuesliding-window

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.