MEDIUMasked at 1 company

Shortest String That Contains Three Strings

A medium-tier problem at 31% community acceptance, tagged with String, Greedy, Enumeration. Reported in interviews at DE Shaw and 0 others.

Founder's read

You're given three strings and need to find the shortest string that contains all three as substrings. DE Shaw has asked this. The acceptance rate is 30%, which signals a trap: the greedy approach fails, and most candidates optimize for the wrong thing. You can brute-force permutations and overlaps, but the trick is recognizing which substrings are already contained in others, then trying all orderings and finding maximum overlap at each step. If you blank on the overlap logic during the live assessment, StealthCoder solves it invisibly in seconds.

Companies asking
1
Difficulty
MEDIUM
Acceptance
31%

Companies that ask "Shortest String That Contains Three Strings"

If this hits your live OA

Shortest String That Contains Three Strings is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.

Get StealthCoder
What this means

The problem looks deceptively simple but punishes greedy thinking. The core insight is that you can't just concatenate the three strings. Instead, try all six permutations of the input strings, and for each permutation, merge them left-to-right by maximizing the overlap between consecutive strings. Overlap means the suffix of the left string matches the prefix of the right string. You also need to handle the case where one string is already a substring of another, which removes it from the merging step. The enumeration of all permutations ensures you find the global minimum. Common failure point: assuming left-to-right greedy order works, or not computing overlap correctly. If this problem lands in your live OA and the overlap math escapes you, StealthCoder surfaces the working solution without the proctor seeing it.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Shortest String That Contains Three Strings recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Shortest String That Contains Three Strings interview FAQ

Is this problem actually asking for a shortest superstring?+

Yes. You're building a minimal string that contains all three inputs as substrings, possibly overlapping. It's the superstring problem on exactly three strings, which is why brute-force enumeration of all orderings is feasible.

What happens if one string is already inside another?+

Remove it from consideration. If 'abc' contains 'bc', you don't need to merge 'bc' separately. Before enumeration, filter out any string that is a substring of another to shrink the search space.

Why is the acceptance rate so low?+

Most candidates try a single greedy merge order or miss the overlap calculation. The trick is permutation-based enumeration combined with a correct overlap function that finds the longest suffix-prefix match. Skipping that detail tanks your solution.

How does overlap merging actually work?+

For two strings A and B, find the longest suffix of A that is a prefix of B. Merge by appending only the non-overlapping part of B. Example: 'abc' and 'bcd' overlap by 2, so result is 'abcd'. Try all overlaps from 0 to min(len(A), len(B)).

Is this a String, Greedy, or Enumeration problem?+

All three. Greedy overlap merging and string manipulation are the core skills, but the overall approach is enumeration of permutations. Greedy alone fails because you need to test all orderings to find the true minimum.

Want the actual problem statement? View "Shortest String That Contains Three Strings" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.