Trains the technique from
LeetCode 27Remove ElementThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A soil probe writes one reading per minute into a fixed buffer samples. One reading value, fault, is a diagnostic code rather than a measurement, so every occurrence of it has to be squeezed out of the buffer.
Rewrite samples in place so that its first kept slots hold exactly the readings that differ from fault, keeping those readings in the order they were recorded. Slots from index kept onward may hold anything; nobody reads them. You may not allocate a second buffer that grows with the input, so the rewrite has to use O(1) extra space.
Because the grader can only inspect a return value, return the pair [kept, samples[:kept]]: the number of surviving readings followed by the surviving prefix itself. The prefix must be in recorded order, so the answer is unique.
Example 1
Three diagnostic codes drop out; the two real readings slide left and keep their recorded order.
Example 2
The buffer starts with a code and holds a run of two more in the middle, so the three survivors compact into the first three slots.
Example 3
No reading matches the code, so nothing moves and the whole buffer survives.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def discard_fault_samples(samples: list[int], fault: int) -> list:public int[] discardFaultSamples(int[] samples, int fault)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.