Conveyor ring rotation
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.
belt_shift_offset(reference: str, observed: str) → int["ABCDE","CDEAB"]out2["ABCDE","ABCDE"]out0["ABC","BAC"]out-1State 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.
["ABCDE","CDEAB"]2not run yetsample["ABCDE","ABCDE"]0not run yetsample["ABC","BAC"]-1not run yetsample