Code RoomChunk overlap length
EasyPrep Room Coding #4708

Chunk overlap length

CodingAlgorithms & data structuresEntry–Mid~14 min

A log shipper reads a file in chunks and deliberately re-sends a little context, so the end of one chunk can repeat the start of the next. Before appending the second chunk the stitcher needs to know how many leading characters to drop. Given two strings tail and head, return the length of the longest string that is both a suffix of tail and a prefix of head. That overlap can be as long as the shorter of the two strings, and it may be the whole of one of them. Return 0 when nothing lines up or when either string is empty. Report the longest overlap, not the first one you happen to find: for tail ababab and head ababcd the answer is 4, not 2.

Implement
overlap_join_length(tail: str, head: str) → int
Examples
in["2026-01-31 boot","boot ok"]out4
in["heartbeat","beat drop"]out4
in["gpu-fan-rpm","temp-c"]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 14 min
InputExpectedGot
["2026-01-31 boot","boot ok"]4not run yetsample
["heartbeat","beat drop"]4not run yetsample
["gpu-fan-rpm","temp-c"]0not run yetsample