Longest prefix reappearing
A serial console capture from a test rig sometimes hides a reboot nobody noticed, because the board prints the same startup banner every time it comes up. The banner is whatever text the capture opens with, and its length was never recorded, so the tool hunts for the longest opening stretch that turns up again further on. Given capture, return the length of the longest prefix of capture that also appears in full starting at some later position. The second copy is allowed to overlap the first, so a capture of four identical characters answers 3. Matching is exact and case sensitive. Return 0 when no prefix reappears, when the capture holds a single character, and when the capture is empty.
boot_banner_echo_length(capture: str) → int["BOOT v2 ready. temp ok. BOOT v2 ready. temp high."]out20["aaaa"]out3["abcdef"]out0State 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.
["BOOT v2 ready. temp ok. BOOT v2 ready. temp high."]20not run yetsample["aaaa"]3not run yetsample["abcdef"]0not run yetsample