FastPrepUnderline Shortest Unique Substrings
Problems/Underline Shortest Unique Substrings

Underline Shortest Unique Substrings

Moveworks logoMoveworks● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported task identifies this algorithmic exercise. The executable interface, bounds, deterministic tie rules, and examples are the documented practice contract.

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.

More Moveworks problems

  • Word BreakONSITE INTERVIEW · Seen Sep 2026
  • Minimum Moves to Sort ArrayOA · Seen Jul 2024
  • Number of Balanced StringsOA · Seen Jul 2024
All Moveworks interview questionsSee Moveworks hiring insights
Saved
class Solution {
    public String[] underlineShortestUniqueSubstrings(String[] strings) {
        // Write your code here.
    }
}
Checking account…