In a Web UI dropdown, users needed help quickly memorizing keyboard shortcuts. For every string in an input list, find its shortest unique substring and wrap that substring with the tags <u> and </u>. Implement a function that performs this transformation.
The detailed requirements were:
-
Uniqueness: The chosen substring must not appear anywhere as a substring of any other string in the input list.
-
Shortest length: Among all unique substrings, choose one with the smallest length.
-
Conflict handling: If several shortest unique substrings have the same length, choose the one that appears earliest in the original string.
-
Case-insensitive matching: Ignore case when matching substrings and checking uniqueness.
-
Preserve the original: In the returned list, every character must retain its original capitalization, and the order of the list must remain the same as the input.
Example:
Input: ["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"]
Discussion
Loading comments…