Underline Shortest Unique Substrings
Reported by candidates from Moveworks's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Moveworks OA reported in September 2026 looks like string formatting, but it's really a substring counting problem wearing a costume. You get up to 200 strings of up to 200 letters each, and you need the shortest substring in each one that shows up in no other string. The data structure that carries the whole solution is a hash map from lowercase substring to the set of string indices that contain it. Build that once and every lookup is cheap. If you blank mid-assessment, StealthCoder is the safety net running invisibly on your screen.
The problem
Given an array of nonempty strings, transform every string by underlining its shortest substring that occurs in none of the other strings. Compare substrings case-insensitively. If several shortest substrings qualify, choose the one whose occurrence starts earliest in the current string. Preserve each string's original casing and preserve the input order. Wrap only the selected occurrence in the literal tags <u> and </u>. If a string has no qualifying substring, return it unchanged. Return the transformed strings. Function underlineShortestUniqueSubstrings(strings: String[]) → String[] Examples Example 1 strings = ["Bird","Cat","Cow","Dog","Wallaby"] return = ["B<u>i</u>rd","Ca<u>t</u>","<u>Co</u>w","Do<u>g</u>","Wa<u>l</u>laby"] For Bird, b also appears in Wallaby, while i appears in no other string, so the earliest shortest choice is i. For Cow, every single letter appears elsewhere, and Co is the earliest qualifying substring of length two. The other strings have the shown unique single-letter choices. Example 2 strings = ["Rose","rose"] return = ["Rose","rose"] Comparison ignores case, so every substring of either string occurs in the other. Both strings remain unchanged. Constraints 1 <= strings.length <= 200. 1 <= strings[i].length <= 200. Every input string contains only uppercase or lowercase ASCII letters. The inserted underline tags do not participate in comparisons.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to lowercase everything and map each substring to the set of string indices it appears in, not a raw count. A raw count breaks when a string repeats a substring internally, since "aa" contains "a" twice but it's still only one string. Then for each string, scan lengths from 1 upward, and within each length scan start positions left to right. The first substring whose set has size exactly 1 wins, which handles the earliest-start tiebreak for free. Wrap that occurrence in <u> tags using the original casing from the original string, not the lowercased copy. Total substrings are about 200 * 20,000 = 4 million, which is fine if you store only the index sets or a last-seen index plus a flag. Pitfall: building the tagged output before comparing. The tags never participate. StealthCoder is the hedge if the hashing and tiebreak logic tangles under the clock.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Underline Shortest Unique Substrings cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Moveworks's OA.
Moveworks reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Underline Shortest Unique Substrings FAQ
What's the trick in the Moveworks underline shortest unique substring problem?+
Lowercase every string, then map each substring to the set of string indices containing it. A substring is unique to a string if its set has size one. Scan lengths ascending and starts left to right, and the first hit is your answer.
Why does Example 2 return both strings unchanged?+
Comparison is case-insensitive, so Rose and rose are identical after lowercasing. Every substring of one occurs in the other, so nothing qualifies. The function returns each string exactly as given, with original casing and no tags.
How do I avoid counting a substring twice within the same string?+
Track which string index owns each substring instead of counting occurrences. Store the first owner index and a flag for shared. If the same string hits it again, the owner matches and you leave the flag alone. Only a different index marks it shared.
Will brute force pass the constraints?+
Probably not if you recompare each candidate against all other strings. The hash map approach touches about 4 million substrings total. Memory is the concern, so store compact entries like an owner index and shared flag rather than full sets of indices.
How do I prepare for this in 48 hours?+
Write the substring map version once from scratch. Test on the Bird, Cat, Cow example and the Rose, rose case. Then check edge cases: a single string input where the first character wins, and a string with no unique substring. Keep the original casing when inserting tags.