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
Coding & Algorithms
Software Engineer
Qualcomm
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

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
ring buffer
modular arithmetic
prefix sums
data structure design
bounded memory
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 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 Problems
Sample Answer
Requirements
  • push(x): O(1), overwrites the oldest when full and increments dropped.
  • 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...


Submit Your Answer
Markdown supported

Related Questions