Code RoomRepeating tape pattern
EasyPrep Room Coding #4709

Repeating tape pattern

CodingAlgorithms & data structuresEntry–Mid~15 min

A warehouse label printer fills a roll of tape by stamping one base code over and over, end to end, with no gap and no partial stamp at the end. Given the finished tape as a string, recover the shortest base code that could have produced it. A base code tiles the tape only when its length divides the length of the tape and repeating it a whole number of times reproduces the tape character for character. Every tape is tiled by itself, so when no shorter code works return the whole tape. Return an empty string for an empty tape. For the tape hb-hb-hb- the answer is hb-, for lot9lot9lot9 it is lot9, and for xyxyxyx it is the whole tape because seven leaves no room for a repeat.

Implement
shortest_tiling_unit(tape: str) → str
Examples
in["hb-hb-hb-"]out"hb-"
in["lot9lot9lot9"]out"lot9"
in["order-42"]out"order-42"
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 15 min
InputExpectedGot
["hb-hb-hb-"]"hb-"not run yetsample
["lot9lot9lot9"]"lot9"not run yetsample
["order-42"]"order-42"not run yetsample