You are processing data from a single security camera.
You are given:
T
(a real number).
[time, motion_level]
, where:
time
is a strictly increasing integer timestamp (in seconds),
motion_level
is a real number.
Whenever motion_level > T, we consider the camera to be "active". Consecutive active readings form a continuous active interval from the time of the first active reading to the time of the last active reading in that group.
Assume:
time
in strictly increasing order.
motion_level <= T
), it does not belong to any active interval.
Return a list of active time intervals [start_time, end_time] covering all maximal contiguous segments of readings where motion_level > T.
Example:
readings = [[1, 0.4], [5, 0.2], [11, 0.9], [15, 0.9], [17, 0.8], [25, 0.5], [27, 0.8], [36, 0.9]]
T = 0.8
[[11, 17], [27, 36]]
Explanation:
motion_level > 0.8
, so they form one interval
[11, 17]
.
motion_level > 0.8
, forming interval
[27, 36]
.
motion_level <= 0.8
and are ignored.
Implement a function that takes the readings and threshold and returns the list of such intervals.