Rolling Average Vape Alerts With Hysteresis on Air Sensors

Last updated: November 29, 2026

Quick Overview

An environmental sensor reports (timestamp, value) readings in time order. Fire an alert when the rolling mean over the last `window` seconds goes above `high`, and do not fire again until the mean has dropped below `low`.

Verkada
Coding & Algorithms
Software Engineer
Verkada
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


An environmental sensor reports (timestamp, value) readings in time order. Fire an alert when the rolling mean over the last `window` seconds goes above `high`, and do not fire again until the mean has dropped below `low`.

Verkada's air quality sensors are deployed in school bathrooms for vape detection, where one noisy spike should not page a principal and a sustained event should page exactly once. The interviewer is checking a time-based sliding window, not a count-based one, and that you avoid alert storms.

What the Interviewer Expects
  • Uses a time-based window with a deque and running sum, not recomputing the mean
  • Explains why hysteresis (two thresholds) prevents flapping
  • Handles irregular sample spacing correctly
  • Keeps O(1) amortized work per reading
  • Discusses floating point drift in the running sum
Key Topics to Cover
sliding window
deque
hysteresis
stream processing
IoT sensors
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you also require the mean to stay above `high` for at least 20 seconds before alerting?
  • Readings can arrive late or out of order over a flaky network. What changes?
  • How would you run this for 100k sensors in a stream processor?
  • How would you choose `high` and `low` per room?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Window is in seconds, so a reading at ts covers readings with timestamp in (ts - window, ts]. Samples can be irregular. One alert per excursion: once fired we are disarmed until the mean drops bel...

High-Level Design

Keep a deque of (ts, value) plus a running total. On each reading, append, then pop from the left while the oldest is outside the window. The mean is total / len(deque). A boolean armed implemen...


Submit Your Answer
Markdown supported

Related Questions