Shortest Unique Metric Tag
A metrics platform stores fully-qualified metric names like 'bookings.checkout.success_rate'. Dashboards autocomplete a metric from any contiguous substring of its name, so each metric needs the shortest substring of its own name that does not appear inside any other metric's name. Given a list of metric names, return a list of the same length where the i-th entry is the shortest contiguous substring of metrics[i] that is not a substring of any other metric in the list. If multiple substrings of the same metric tie for the shortest length, return the lexicographically smallest one. If every substring of metrics[i] also appears in some other metric's name, return an empty string for that metric.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
def shortest_unique_metric_tag(metrics): return
A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- medium
- Seniority
- L5
Problem
A metrics platform stores fully-qualified metric names like 'bookings.checkout.success_rate'. Dashboards autocomplete a metric from any contiguous substring of its name, so each metric needs the shortest substring of its own name that does not appear inside any other metric's name. Given a list of metric names, return a list of the same length where the i-th entry is the shortest contiguous substring of metrics[i] that is not a substring of any other metric in the list. If multiple substrings of the same metric tie for the shortest length, return the lexicographically smallest one. If every substring of metrics[i] also appears in some other metric's name, return an empty string for that metric.
Summary
One token per metric. Make it unambiguous.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.