String Matching in an Array

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.

30:00

String Matching in an Array
easy
Free written solution
Topics
Companies

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≤1001 \leq \text{words.length} \leq 100

  • 1≤words[i].length≤301 \leq \text{words}[i]\text{.length} \leq 30

  • words[i]\text{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.

words: candidate, searched, inside another word

mass
as
hero
superhero

no candidate yet

result

[]

Variables
VariableValue
found0
DepthFunction Call
Stack empty
0/19