Code Room
CodingMediumcod-g160
Subject Z algorithmLevel Mid–Senior~20 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A border of a string is a proper prefix that is also a suffix (proper meaning strictly shorter than the whole string). Return the length of the LONGEST border of s. For example "abcabc" has longest border "abc" (length 3), "aaaa" has length 3, and "abcd" has length 0. The empty string has border length 0. The string can be up to 10^5 characters, so aim for linear time.

Implement
longest_border(s: str) → int
Examples
in["abcabc"]out3
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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.