Code RoomConveyor ring rotation
EasyPrep Room Coding #4759

Conveyor ring rotation

CodingAlgorithms & data structuresEntry–Mid~14 min

A bottling plant runs one closed conveyor ring. Each station on the ring is labelled with a single uppercase letter, and a technician writes the ring down by starting beside whichever station they happen to be standing at, then walking with the direction of travel until they arrive back at it. Two write ups of the same ring can therefore begin at different stations. Given reference and observed, return how many stations ahead of the reference the observed write up begins: the smallest k such that reading reference from position k, wrapping past the end, reproduces observed character for character. Return -1 when no such k exists, which includes any case where the two write ups have different lengths. Two empty write ups describe the same empty ring, so return 0.

Implement
belt_shift_offset(reference: str, observed: str) → int
Examples
in["ABCDE","CDEAB"]out2
in["ABCDE","ABCDE"]out0
in["ABC","BAC"]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 14 min
InputExpectedGot
["ABCDE","CDEAB"]2not run yetsample
["ABCDE","ABCDE"]0not run yetsample
["ABC","BAC"]-1not run yetsample