An Anduril sensor pipeline receives an ordered array of integer readings. Given a threshold, find the longest contiguous window whose average reading is at least the threshold.
Return the window as [start, end], using zero-based inclusive indices. If multiple qualifying windows have the same maximum length, return the one with the smallest start index. Return [] if no qualifying window exists.
A solution that checks every pair of endpoints is too slow for the largest inputs. Design an algorithm that runs in linear time.
Implement longest_threshold_window(readings, threshold).
readings is a non-empty list of integers.threshold is an integer.[start, end], or an empty list.sum(readings[start:end + 1]) / (end - start + 1) >= threshold.You may transform each reading by subtracting threshold. The qualifying condition then becomes a non-negative subarray-sum condition.
def longest_threshold_window(readings, threshold):