Rolling Median Filter for Engine Chamber Pressure Sensors
Last updated: November 29, 2026
Quick Overview
Implement a sliding-window median over a stream of chamber pressure readings with window size `k`, returning the median for every full window, so single-sample sensor spikes do not trip an engine abort.
Spacex
November 29, 20260
0
0 solved
Implement a sliding-window median over a stream of chamber pressure readings with window size `k`, returning the median for every full window, so single-sample sensor spikes do not trip an engine abort.
Engine controllers on Merlin and Raptor sample pressure and temperature at high rates, and a mean filter lets one glitched sample drag the value toward a false abort. This onsite question in the SpaceX style tests a non-trivial data structure (two heaps with lazy deletion) and whether you think about determinism and cost per sample.
What the Interviewer Expects
- Explain why a median beats a mean for spike rejection
- Use a max-heap and min-heap split with balanced sizes
- Handle removals of values leaving the window via lazy deletion
- Track valid sizes separately from raw heap lengths
- Give O(log k) amortized per sample and discuss worst-case memory
- Mention a simpler O(k) sorted-array version for small k on embedded targets
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
- For k = 5 on a flight computer, would you still use heaps? Why or why not?
- How would you bound memory if lazy deletions accumulate?
- How do you combine this with a rate-of-change check so a real pressure drop is not hidden?
- How would you test this against a brute-force reference?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of readings and window size k >= 1. Output: median of each of the n - k + 1 full windows as floats (mean of the two middle values when k is even)....
High-Level Design
lo is a max-heap holding the smaller half, hi a min-heap holding the larger half, with valid(lo) == valid(hi) or one more. Removing an arbitrary element from a heap is O(k), so we mark it in `de...