Design CPU-Cycle Window Alignment for Misaligned Time Series
Gimlet LabsMember of Technical Staff, ML Systems · OnsiteLast updated
Define and implement a precise windowing contract for two misaligned CPU-cycle time series using piecewise-linear interpolation, monotone scanning, explicit boundary behavior, and optional interval integration.
Interview Prompt
Design and implement an algorithm that buckets two CPU-cycle time series whose timestamps do not align and produces time windows on a common basis. Treat every segment between adjacent samples as a linear function for interpolation. Before choosing data structures, make the missing contract explicit: window boundaries, endpoint inclusion, whether each window needs a point value or aggregate, behavior outside a series' sampled range, and the required output shape.
Constraints & Assumptions
- Each input series is ordered by CPU-cycle timestamp and adjacent samples define a piecewise-linear segment.
- The two series may have no matching timestamps.
- Window-aligned output must use one explicitly stated timestamp or interval convention for both series.
- Do not silently assume union-of-sample timestamps, overlap-only output, or a particular row schema.
Clarifying Questions to Ask
- Are window boundaries supplied by the caller, fixed-width from an origin, or derived by another rule?
- Does a bucket report a value at one representative timestamp or an average over the interval?
- Should a window without bracketing samples be omitted, marked missing, or extrapolated?
- Which side owns a sample that lands exactly on a boundary?
Follow-up questions
- How would the algorithm change if a bucket needs the time-weighted average rather than a boundary value?
- How would you process streams online when a future sample is needed to close the current linear segment?
- How would you detect counter reset or wraparound in CPU-cycle timestamps?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.