Code RoomSmallest rotation of belt readings
MediumPrep Room Coding #4878

Smallest rotation of belt readings

CodingAlgorithms & data structuresMid–Senior~25 min

A factory presses closed loop timing belts. An inspector reads a belt by walking once around the loop from an arbitrary starting tooth and writing one letter per tooth, so one physical belt can be recorded as any rotation of the same string. Two readings describe the same part when one reading is a rotation of the other, and readings of different lengths are always different parts. The part code of a part is the alphabetically smallest rotation of any of its readings. Given the readings in any order, return the part code of every distinct part, sorted alphabetically. Readings are non-empty lowercase strings and the same reading may be filed more than once.

Implement
belt_part_codes(readings: list[str]) → list[str]
Examples
in[["abc","bca","cab"]]out["abc"]
in[["ab","ba","aab"]]out["aab","ab"]
in[["aaa","aa"]]out["aa","aaa"]
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 25 min
InputExpectedGot
[["abc","bca","cab"]]["abc"]not run yetsample
[["ab","ba","aab"]]["aab","ab"]not run yetsample
[["aaa","aa"]]["aa","aaa"]not run yetsample