Longest repeated frame block

Write codeMedium25 min

Your task

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.

Examples

longest_tandem_burst(capture: str) -> int
Example 1
Inputlongest_tandem_burst("abcabcab")
Output6
Example 2
Inputlongest_tandem_burst("abcxabc")
Output0
Example 3
Inputlongest_tandem_burst("aaaaa")
Output5