← 返回 microsoft 的题目列表Streaming Events Fixed-Interval Window Min/Max Summary
类型:online_judge
Problem: Fixed-Interval Window Min/Max Summary for Streaming Events (Sliding Window Variant)
You are given a sequence of streaming events in chronological order. The system groups events into consecutive fixed-size time windows of length W seconds:
1st window covers [0, W]
2nd window covers (W, 2W]
3rd window covers (2W, 3W]
and so on (endpoint inclusion follows the example).
Each window may contain zero or more events. Each event is represented by a double timestamp (seconds).
For each non-empty window, output a summary tuple:
For the event set session in that window, output (min(session), max(session)).
Return the list of summaries in window order.
Input
Line 1: integer W (window size in seconds)
Line 2: a sequence of timestamps in non-decreasing order (space-separated)
Output
Multiple lines, each with two floating-point numbers min max for a non-empty window, in window order.
Constraints
1 <= W <= 10^9
0 <= n <= 2 * 10^5
Timestamps are double and overall non-decreasing
Expected time complexity: O(n)
Example
Input:
2
0.5 1 1.5 2.0 4.0
Output:
0.5 2.0
4.0 4.0
Example
Input
2
0.5 1 1.5 2.0 4.0
Output
0.5 2.0
4.0 4.0