All problems
MediumData & Featuresv2026-06-30

Data & Features ยท Medium

Time-Window Aggregation

Aggregate timestamped values into fixed windows while preserving empty gaps.

Task

Implement time_window_aggregation(timestamps: list[int], values: list[float], window_size: int, origin: int) -> tuple[list[int], list[float], list[int]]. Aggregate sorted timestamped values into consecutive fixed-width windows, returning every window start, value sum, and event count through the last event.

Requirements

  • timestamps and values have equal length, timestamps are sorted in non-decreasing order, and every timestamp is at least origin.
  • window_size is a positive integer.
  • Window k starts at origin + k * window_size and includes timestamps in [start, start + window_size).
  • A timestamp exactly on a window's right boundary belongs to the next window.
  • Return windows from origin through the window containing the final event.
  • Include empty windows between events with sum 0.0 and count 0.
  • Accumulate duplicate timestamps independently.
  • Preserve floating-point values, including negative values.
  • Return three empty lists for empty input and do not mutate either input.

Example

time_window_aggregation(
    [0, 1, 4, 5, 9],
    [1.0, 2.0, 3.0, 4.0, 5.0],
    5,
    0,
)
# ([0, 5], [6.0, 9.0], [3, 2])
solution.pySign in to save
Public tests run locally in your browser.
Run your code to see public test results.