Given an array of string words. Return all strings in words which is substring of another word in any order.&nbsp;

String words[i] is substring of words[j],&nbsp;if&nbsp;can be obtained removing some characters to left and/or right side of words[j].

&nbsp;
Example 1:

Input: words = ["mass","as","hero","superhero"]
Output: ["as","hero"]
Explanation: "as" is substring of "mass" and "hero" is substring of "superhero".
["hero","as"] is also a valid answer.


Example 2:

Input: words = ["leetcode","et","code"]
Output: ["et","code"]
Explanation: "et", "code" are substring of "leetcode".


Example 3:

Input: words = ["blue","green","bu"]
Output: []


&nbsp;
Constraints:


	1 &lt;= words.length &lt;= 100
	1 &lt;= words[i].length &lt;= 30
	words[i] contains only lowercase English letters.
	It's guaranteed&nbsp;that words[i]&nbsp;will be unique.


class Solution:
    def stringMatching(self, words: List[str]) -> List[str]:
        ans=set()
        l=len(words)
        for i in range(l):
            for j in range(l):
                if (words[i] in words[j]) & (i!=j):
                    ans.add(words[i])
        return ans
class Solution {
    public List<String> stringMatching(String[] words) {
        List<String>ans = new ArrayList<>();
        for(int i=0; i<words.length; i++){
            String s = words[i];
            for(int j=0; j<words.length; j++){
                if(i == j){
                    continue;
                }
                if(words[j].indexOf(s) >= 0){
                    ans.add(s);
                    break;
                }
            }
        }
        return ans;
    }
}
class Solution {
public:
    vector<string> stringMatching(vector<string>& words) {
        vector<string> res; //output

        for(int i = 0 ; i < words.size(); i++)
        {
            for(int j = 0; j < words.size(); j++)
            {
                if(i != j && words[j].find(words[i]) != -1)
                {
                    if(!count(res.begin(),res.end(), words[i])) //if vector result does not include this string, push it to vector
                        res.push_back(words[i]);
                    else
                        continue; //if vector result includes this string, ignore
                }
            }
        }
        
        return res;
    }
};
var stringMatching = function(words) {
    let res = [];

    for (let i = 0; i < words.length; i++) {

        for (let j = 0; j < words.length; j++) {
            if (j === i) continue;

            if (words[j].includes(words[i])) {
                res.push(words[i]);
                break;
            }

        }
    }

    return res;
};
String Matching in an Array