Find High-Intensity Time Periods
Company: Hot Agent Startup
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates processing of time-series step-function data, detection of maximal intervals where a numeric intensity exceeds a threshold, and edge-case reasoning such as duplicate timestamps and observation-end boundaries within the Coding & Algorithms category.
Constraints
- 0 <= n <= 200000, where n is the number of readings
- timestamps, intensities, threshold, and observationEnd are integers
- Timestamps are not guaranteed to be unique
- Intervals starting at or after observationEnd contribute nothing
- If multiple readings share the same timestamp, the last one in the input wins
Examples
Input: ([{'timestamp': 1, 'intensity': 3}, {'timestamp': 4, 'intensity': 8}, {'timestamp': 7, 'intensity': 9}, {'timestamp': 10, 'intensity': 2}, {'timestamp': 13, 'intensity': 6}], 5, 15)
Expected Output: [[4, 10], [13, 15]]
Explanation: Intensity is above 5 from [4, 7) and [7, 10), which merge into [4, 10). It is above 5 again from [13, 15).
Input: ([], 5, 10)
Expected Output: []
Explanation: With no readings, there are no intervals above the threshold.
Input: ([{'timestamp': 0, 'intensity': 5}, {'timestamp': 3, 'intensity': 6}, {'timestamp': 5, 'intensity': 5}], 5, 8)
Expected Output: [[3, 5]]
Explanation: Intensity equal to the threshold does not count. Only [3, 5) is strictly above 5.
Input: ([{'timestamp': 1, 'intensity': 7}, {'timestamp': 1, 'intensity': 4}, {'timestamp': 2, 'intensity': 9}, {'timestamp': 4, 'intensity': 1}], 5, 6)
Expected Output: [[2, 4]]
Explanation: At timestamp 1, the last reading wins, so intensity 4 is effective from [1, 2). Only [2, 4) is above the threshold.
Input: ([{'timestamp': 5, 'intensity': 1}, {'timestamp': 1, 'intensity': 7}, {'timestamp': 3, 'intensity': 2}, {'timestamp': 4, 'intensity': 8}], 5, 6)
Expected Output: [[1, 3], [4, 5]]
Explanation: After sorting by timestamp, the effective segments are [1, 3) with intensity 7, [3, 4) with 2, [4, 5) with 8, and [5, 6) with 1.
Input: ([{'timestamp': 1, 'intensity': 8}, {'timestamp': 5, 'intensity': 3}], 5, 4)
Expected Output: [[1, 4]]
Explanation: The first reading is above the threshold, but the interval is truncated by observationEnd, so the answer is [1, 4).
Hints
- Think of each effective reading as defining a segment from its timestamp to the next timestamp (or observationEnd for the last reading).
- If the input can be unsorted or contain duplicate timestamps, normalize it first by sorting and collapsing equal timestamps.