← 返回 meta 的题目列表Find Words That Are Substrings of Other Words
类型:online_judge
Given an array of strings words (may contain duplicates), return all words that are a substring of another word in the array.
Return the list of matching words (order does not matter). This version requires deduplication in the output.
Requirements:
Provide a baseline approach and analyze its time and space complexity.
Propose an optimized approach, give its expected time/space complexity, and implement it.
Constraints:
1 <= len(words) <= 2 * 10^4
1 <= len(words[i]) <= 10^3
lowercase English letters only
Example:
Input: ["category", "cat"]
Output: ["cat"]
Provide at least 5 test cases including duplicates, identical strings, and a no-match case.
Example
Input
words=["category","cat"]
Output
["cat"]