Code RoomLongest prefix reappearing
EasyPrep Room Coding #4828

Longest prefix reappearing

CodingAlgorithms & data structuresEntry–Mid~13 min

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.

Implement
boot_banner_echo_length(capture: str) → int
Examples
in["BOOT v2 ready. temp ok. BOOT v2 ready. temp high."]out20
in["aaaa"]out3
in["abcdef"]out0
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 13 min
InputExpectedGot
["BOOT v2 ready. temp ok. BOOT v2 ready. temp high."]20not run yetsample
["aaaa"]3not run yetsample
["abcdef"]0not run yetsample