Fixed Capacity Ring Buffer for Sensor Hub Samples
Last updated: November 29, 2026
Quick Overview
Design a ring buffer for a low-power sensor hub with a fixed capacity that overwrites the oldest sample when full, supports popping the oldest sample, returning the latest k samples, and returning the mean of the latest k samples in O(1). Track how many samples were dropped by overwrite.
Qualcomm
November 29, 20260
0
0 solved
Design a ring buffer for a low-power sensor hub with a fixed capacity that overwrites the oldest sample when full, supports popping the oldest sample, returning the latest k samples, and returning the mean of the latest k samples in O(1). Track how many samples were dropped by overwrite.
Qualcomm's Sensing Hub on Snapdragon batches accelerometer and gyro data in always-on, tightly bounded memory before waking the application processor. The interviewer looks for clean index arithmetic, a clear full versus empty distinction, and an O(1) windowed statistic without unbounded memory growth.
What the Interviewer Expects
- Uses head plus size (or head and tail plus a flag) to tell full from empty
- Overwrites the oldest sample on a full push and counts drops
- Computes the latest-k mean in O(1) with prefix sums or running sums
- Keeps auxiliary memory bounded, not growing with total samples
- Validates k and empty-buffer operations
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you make push and pop safe with one producer (sensor ISR) and one consumer (thread) without locks?
- Why do many embedded ring buffers use power-of-two capacities?
- How would you also support the max of the latest k samples?
- Prefix sums of floats drift over long runs. How would you avoid that?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
push(x): O(1), overwrites the oldest when full and incrementsdropped.pop_oldest(): O(1), error when empty.latest(k): the newest k samples, oldest first.mean_latest(k): O(1).- Me...
High-Level Design
Store samples in a fixed array with head (oldest) and size. The next write slot is (head + size) % cap. For the mean, keep a prefix-sum list over the global push sequence, since the newest k sam...