Code Room
CodingEasycod-g1404
Subject Two pointersLevel Entry–Mid~10 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.