← Questions

Merge two strings on their longest overlap

0
AppleCodingLast asked Sep 2026

Given two strings, join them so that the longest overlap between the end of one and the start of the other appears only once. Try both orders (first then second, and second then first), and keep the order with the longer overlap; on a tie, put the first string first. Return the merged string. Start with the direct approach, then make finding the overlap efficient (a prefix function or hashing).

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding