Code RoomNext pattern in sweep
HardPrep Room Coding #4895

Next pattern in sweep

CodingML systemsAlgorithms & data structuresSenior–Staff~32 min

A soak test rig energizes relay lines in patterns. Bit i of a pattern is set when line i is energized, and slots gives how many lines the rig has, at most 30. A sweep visits every pattern that energizes exactly as many lines as the one it began with, taking them in ascending numeric order. The log names pattern as the last one that finished, and says skipped further patterns ran unrecorded before the rig died. Return the pattern the rig should restart from, the one sitting skipped places after pattern in that ascending order, or -1 when the order runs out first. A skipped of 0 asks for pattern itself. skipped can reach into the hundreds of millions, so stepping one pattern at a time will not finish.

Implement
resume_sweep_pattern(pattern: int, slots: int, skipped: int) → int
Examples
in[5,4,1]out6
in[3,3,2]out6
in[12,4,1]out-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 32 min
InputExpectedGot
[5,4,1]6not run yetsample
[3,3,2]6not run yetsample
[12,4,1]-1not run yetsample