Given an array of distinct strings words, return every string in words that appears as a substring of some other string in words. A substring is a contiguous run of characters inside a string. You may return the answer in any order.
Given an array of distinct strings words, return every string in words that appears as a substring of some other string in words. A substring is a contiguous run of characters inside a string. You may return the answer in any order.
Example 1:
Input: {"words":["mass","as","hero","superhero"]}
Output: ["as","hero"]
Constraints:
1≤words.length≤100
1≤words[i].length≤30
words[i] contains only lowercase English letters.
All the strings of words are unique.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"words":["mass","as","hero","superhero"]}
Check each of the 4 words: is it hidden inside any other word? Collect the ones that are.