Quick Overview

Find the shortest case-insensitive substring unique to each label, break ties by earliest position, and mark that occurrence without changing the original text or case.

Highlight the Shortest Unique Substring in Each Label

Company: Atlassian

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem For every label in a dropdown, find a short case-insensitive mnemonic that does not occur as a substring of any other label. Wrap the chosen characters in the literal tags `<u>` and `</u>` while preserving the label's original characters and case. ## Function Contract Implement `highlight_unique_substrings(labels)` and return the highlighted labels in input order. ## Rules - A candidate is unique only when its lowercase form is absent from every other lowercase label. - Choose the shortest unique candidate; among candidates of that length, choose the earliest starting position. - Occurrences elsewhere in the same label do not disqualify a candidate. - If a label has no unique substring, return it unchanged. - Insert exactly one opening tag and one closing tag around the selected occurrence. ## Constraints - `1 <= len(labels) <= 1000`. - Each label has length from 1 to 100 and contains ASCII letters only. - The sum of label lengths is at most `10000`. ## Examples ```text labels = ["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"] ```

Quick Answer: Find the shortest case-insensitive substring unique to each label, break ties by earliest position, and mark that occurrence without changing the original text or case.

For each dropdown label, find a case-insensitive substring that does not occur in any other label. Choose the shortest such substring and, among candidates of equal length, the earliest starting position. Occurrences elsewhere in the same label do not disqualify a candidate. Wrap exactly the chosen occurrence in the literal tags <u> and </u>, preserving the label's original characters and case. If a label has no unique substring, return it unchanged. Return highlighted labels in input order.

Constraints

  • 1 <= len(labels) <= 1000.
  • Each label has length 1 through 100 and contains ASCII letters only.
  • The sum of all label lengths is at most 10000.
  • Uniqueness comparisons are case-insensitive, but output preserves original characters and input order.

Examples

Input: (['Bird', 'Cat', 'Cow', 'Dog', 'Wallaby'],)

Expected Output: ['B<u>i</u>rd', 'Ca<u>t</u>', '<u>Co</u>w', 'Do<u>g</u>', 'Wa<u>l</u>laby']

Explanation: Each label receives its shortest earliest case-insensitive unique substring.

Input: (['Alpha'],)

Expected Output: ['<u>A</u>lpha']

Explanation: With one label, its first character is already unique.

Hints

  1. Count a substring at most once per label, even when it occurs repeatedly within that label.
  2. Search candidate lengths from shortest to longest and starts from left to right.

Loading coding console...