Fixed Capacity IMU Sample Window With Constant Time Mean

Last updated: November 29, 2026

Quick Overview

Implement a fixed-capacity window over IMU accelerometer samples that supports push, mean of the samples currently held, and the n most recent samples, all without allocating after construction.

Shield AI
Coding & Algorithms
Software Engineer
Shield AI
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Implement a fixed-capacity window over IMU accelerometer samples that supports push, mean of the samples currently held, and the n most recent samples, all without allocating after construction.

Onboard autonomy code at Shield AI runs on embedded flight computers where allocation in the control loop is avoided, so a ring buffer is a natural warm-up. The interviewer checks index arithmetic, overwrite semantics, and that you keep a running sum instead of re-summing.

What the Interviewer Expects
  • Preallocates storage and tracks head and size
  • Subtracts the overwritten sample from the running sum
  • Returns recent samples in chronological order
  • Rejects zero capacity and empty mean with clear errors
  • Mentions float drift in a long running sum and how to correct it
Key Topics to Cover
Ring buffer
Running statistics
Embedded constraints
Index arithmetic
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 this safe for one producer thread (the IMU driver) and one consumer (the estimator)?
  • The running sum drifts after millions of samples. How do you bound the error?
  • Add a variance query in O(1).
  • How would you write this in C++ with no heap allocation at all?
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) adds a sample, overwriting the oldest when full. mean() returns the average of the held samples. latest(n) returns up to n most recent samples, oldest first. All operations should be O(1...

High-Level Design

Use a fixed array, a head index that points at the next write slot, a size counter, and a running total. When the buffer is full, the slot at head holds the oldest sample, so subtract it befor...


Submit Your Answer
Markdown supported

Related Questions