Code RoomSustained faults across spans
MediumPrep Room Coding #4891

Sustained faults across spans

CodingAlgorithms & data structuresMid–Senior~20 min

A motor controller reports a fault word once per tick, bit f standing for fault f, and faults are numbered 0 to 29. The console only trusts a fault it has watched hold, so it calls a fault sustained over a stretch of ticks when that fault is active in every single tick of the stretch. frames holds the words in tick order and span gives how many consecutive ticks a stretch covers, always at least one. Return one word per stretch, in the order the stretches begin, holding exactly the faults sustained across that stretch. frames can run to a hundred thousand words and span can be almost as long, so rebuilding a stretch from scratch is too slow. Return an empty list when span is longer than the run of frames.

Implement
sustained_fault_masks(frames: list[int], span: int) → list[int]
Examples
in[[7,6,14],2]out[6,6]
in[[1,2,4],1]out[1,2,4]
in[[5,5,5,1],3]out[5,1]
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 20 min
InputExpectedGot
[[7,6,14],2][6,6]not run yetsample
[[1,2,4],1][1,2,4]not run yetsample
[[5,5,5,1],3][5,1]not run yetsample