Skip to main content
All Questions

Concatenate two strings, writing their longest shared end and start only once.

Unlock detailed company stats for this questionUpgrade

Factorize the extremities of two ASCII strings str1 and str2. Return a single string initially made from the concatenation of the two given strings, where the longest substring common to the end of the first string and the beginning of the second one is factorized (written only once). Decide the concatenation order (str1 + str2 or str2 + str1) so that you get the best factorization. When both orders factorize the same number of characters, prioritize str1 + str2.

Example: str1 = "1234yyabc", str2 = "abcxxxx1234" returns "abcxxxx1234yyabc" (factorizing "abc" via the str2 + str1 order).

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.