Problem: String Matching in an Array
You are given an array of strings words. Your task is to find all the strings in the array that are a substring of another string in the same array. Return these strings in any order.
Key Points:
- A substring is a part of another string. For example, "as" is a substring of "mass".
- We are looking for strings in the array that can be found as substrings within other strings in the array.
Examples:
Example 1:
Input:
words = ["mass", "as", "hero", "superhero"]
Output:
["as", "hero"]
Explanation:
- "as" is a substring of "mass".
- "hero" is a substring of "superhero".
- The order of the output does not matter. For example,
["hero", "as"] is also correct.
Example 2:
Input:
words = ["leetcode", "et", "code"]
Output:
["et", "code"]
Explanation:
- "et" is a substring of "leetcode".
- "code" is a substring of "leetcode".
Example 3:
Input:
words = ["blue", "green", "bu"]
Output:
[]
Explanation:
No string in the array is a substring of another string.
Constraints:
1≤words.length≤1001≤words[i].length≤30Each string in words contains only lowercase English letters.All strings in words are unique.
What to Do:
- Go through each string in the array.
- Check if it is a substring of any other string in the array.
- Collect all such strings and return them in any order.
Output:
The output is an array containing strings that are substrings of other strings in the input array.