algoblazerEarly Access
LearnProblemsLeaderboard
Log inSign up

All problems

‹ Back to map
1 shown · 0/261 solved

Highlight Unique Substrings

SilverCommunity Beta
Asked atAtlassian
Solve problem →
5000ms256MBAdded Aug 15, 2026

You are given an array of strings entries.

Call a substring unique to an entry if, comparing case-insensitively, it occurs as a substring of that entry and of no other entry in the array. Occurring several times inside its own entry is fine.

For each entry, find its shortest unique substring. If several unique substrings share the shortest length, use the one that starts earliest in the entry. Wrap that occurrence in <u> and </u>.

Return the array with every entry marked this way, in the original order and with the original casing preserved.

It is guaranteed that every entry has at least one unique substring.

Examples

Example 1

Input: entries = ["Bird", "Cat", "Cow", "Dog", "Wallaby"]
Output: ["B<u>i</u>rd", "Ca<u>t</u>", "<u>Co</u>w", "Do<u>g</u>", "Wa<u>l</u>laby"]
Explanation:
"Bird": "b" also occurs in "Wallaby", so the first unique 1-letter substring is "i".
"Cow": every single letter occurs elsewhere ("c" in "Cat", "o" in "Dog", "w" in
"Wallaby"), so the answer has length 2; "Co" starts earlier than "ow".
"Wallaby": "l" is unique; its first occurrence is marked.
Read full statement →

Constraints

  • 1≤1 \leq1≤ entries.length ≤200\leq 200≤200
  • 1≤1 \leq1≤ entries[i].length ≤100\leq 100≤100
  • entries[i] consist of English letters and digits
  • every entry has at least one unique substring

Details

Solved by3 people
Time limit5000ms
Memory256MB
AddedAug 15, 20263 weeks ago