Remove failed samples
A fitness band streams non-negative sensor readings, but a failed sample is recorded as -1. Given the readings list, remove every failed sample while keeping the valid readings in their original order, and return the compacted list. Do it in a single pass using a write pointer (overwrite the array in place, then cut it to length) rather than building a filtered copy per element check. Example: [7, -1, 8, -1, -1, 9] becomes [7, 8, 9].
Implement
compact_readings(readings: list[int]) → list[int]Examples
in
[[7,-1,8,-1,-1,9]]out[7,8,9]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 10 min
solution.py
InputExpectedGot
[[7,-1,8,-1,-1,9]][7,8,9]not run yetsample