Code RoomLongest repeated frame block
MediumPrep Room Coding #4888

Longest repeated frame block

CodingAlgorithms & data structuresMid–Senior~25 min

A link tester records the frames a radio receives as one string, one letter per frame type. When the link stutters the receiver takes a block of frames and then immediately takes the very same block again, sometimes several times over, with nothing in between. Given the capture, return the length of the longest stretch that is one block written two or more times back to back. Such a stretch is always a whole number of copies, so its length is a multiple of its block length. Return 0 when no stretch qualifies. Copies have to be adjacent: in abcxabc the two copies of abc are separated, so nothing qualifies, while abcabcab answers 6. A run of one letter counts too, since a single letter is a block, so aaaaa answers 5.

Implement
longest_tandem_burst(capture: str) → int
Examples
in["abcabcab"]out6
in["abcxabc"]out0
in["aaaaa"]out5
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
["abcabcab"]6not run yetsample
["abcxabc"]0not run yetsample
["aaaaa"]5not run yetsample