Zoox autonomy services may receive long sequences of nearly identical sensor readings. Implement an in-place compressor that removes redundant readings while preserving the original order and minimizing memory use.
A reading is represented as [timestamp, x, y]. Always retain the first reading. For every later reading, retain it if either of these conditions is true:
max_interval.x or y from the last retained reading is greater than epsilon.Write retained readings into the beginning of the original readings list. Do not allocate a second list, and do not delete or resize the unused suffix. Return the number of retained readings. The valid compressed output is the prefix readings[:returned_count].
Implement compress_sensor_stream(readings, epsilon, max_interval), where readings is a mutable list of three-element numeric lists. The function returns an integer count and mutates readings in place.
def compress_sensor_stream(readings, epsilon, max_interval):