Find Motion Periods
Written by a community member · · 1 attempt · 0% pass
A surveillance camera records chronologically ordered timestamps and motion intensity readings. Given parallel arrays times and intensities, along with a sensitivity threshold, return every contiguous run of readings whose intensity is at least the threshold. Each run starts at the timestamp of its first qualifying reading and ends at the timestamp of its last qualifying reading. Readings are considered contiguous by their position in the arrays, regardless of gaps between timestamps. Both endpoints are inclusive, so a run containing one reading is [t, t]. Return the periods as [start, end] pairs in ascending start-time order, or an empty list if there are no qualifying readings.
Assume times and intensities have equal length and times is in nondecreasing chronological order.
Example 1: times = [1, 2, 7, 8, 12], intensities = [3, 5, 4, 6, 2], threshold = 5 returns [[2, 2], [8, 8]].
Example 2: times = [10, 11, 15, 16], intensities = [5, 7, 8, 4], threshold = 5 returns [[10, 15]].
Constraints: 0 <= len(times) == len(intensities) <= 100000; timestamps and intensities are integers; timestamps are chronologically ordered; threshold is an integer.