3076. Shortest Uncommon Substring in an Array Medium
1/**
2 * [3076] Shortest Uncommon Substring in an Array
3 *
4 * You are given an array arr of size n consisting of non-empty strings.
5 * Find a string array answer of size n such that:
6 *
7 * answer[i] is the shortest <span data-keyword="substring">substring</span> of arr[i] that does not occur as a substring in any other string in arr. If multiple such substrings exist, answer[i] should be the <span data-keyword="lexicographically-smaller-string">lexicographically smallest</span>. And if no such substring exists, answer[i] should be an empty string.
8 *
9 * Return the array answer.
10 *
11 * <strong class="example">Example 1:
12 *
13 * Input: arr = ["cab","ad","bad","c"]
14 * Output: ["ab","","ba",""]
15 * Explanation: We have the following:
16 * - For the string "cab", the shortest substring that does not occur in any other string is either "ca" or "ab", we choose the lexicographically smaller substring, which is "ab".
17 * - For the string "ad", there is no substring that does not occur in any other string.
18 * - For the string "bad", the shortest substring that does not occur in any other string is "ba".
19 * - For the string "c", there is no substring that does not occur in any other string.
20 *
21 * <strong class="example">Example 2:
22 *
23 * Input: arr = ["abc","bcd","abcd"]
24 * Output: ["","","abcd"]
25 * Explanation: We have the following:
26 * - For the string "abc", there is no substring that does not occur in any other string.
27 * - For the string "bcd", there is no substring that does not occur in any other string.
28 * - For the string "abcd", the shortest substring that does not occur in any other string is "abcd".
29 *
30 *
31 * Constraints:
32 *
33 * n == arr.length
34 * 2 <= n <= 100
35 * 1 <= arr[i].length <= 20
36 * arr[i] consists only of lowercase English letters.
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/shortest-uncommon-substring-in-an-array/
42// discuss: https://leetcode.com/problems/shortest-uncommon-substring-in-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn shortest_substrings(arr: Vec<String>) -> Vec<String> {
48 vec![]
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_3076() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.