<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p>

<p>Find a string array <code>answer</code> of size <code>n</code> such that:</p>

<ul>
	<li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of <code>arr[i]</code> that does <strong>not</strong> occur as a substring in any other string in <code>arr</code>. If multiple such substrings exist, <code>answer[i]</code> should be the <span data-keyword="lexicographically-smaller-string">lexicographically smallest</span>. And if no such substring exists, <code>answer[i]</code> should be an empty string.</li>
</ul>

<p>Return <em>the array </em><code>answer</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> arr = [&quot;cab&quot;,&quot;ad&quot;,&quot;bad&quot;,&quot;c&quot;]
<strong>Output:</strong> [&quot;ab&quot;,&quot;&quot;,&quot;ba&quot;,&quot;&quot;]
<strong>Explanation:</strong> We have the following:
- For the string &quot;cab&quot;, the shortest substring that does not occur in any other string is either &quot;ca&quot; or &quot;ab&quot;, we choose the lexicographically smaller substring, which is &quot;ab&quot;.
- For the string &quot;ad&quot;, there is no substring that does not occur in any other string.
- For the string &quot;bad&quot;, the shortest substring that does not occur in any other string is &quot;ba&quot;.
- For the string &quot;c&quot;, there is no substring that does not occur in any other string.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> arr = [&quot;abc&quot;,&quot;bcd&quot;,&quot;abcd&quot;]
<strong>Output:</strong> [&quot;&quot;,&quot;&quot;,&quot;abcd&quot;]
<strong>Explanation:</strong> We have the following:
- For the string &quot;abc&quot;, there is no substring that does not occur in any other string.
- For the string &quot;bcd&quot;, there is no substring that does not occur in any other string.
- For the string &quot;abcd&quot;, the shortest substring that does not occur in any other string is &quot;abcd&quot;.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == arr.length</code></li>
	<li><code>2 &lt;= n &lt;= 100</code></li>
	<li><code>1 &lt;= arr[i].length &lt;= 20</code></li>
	<li><code>arr[i]</code> consists only of lowercase English letters.</li>
</ul>

class Solution:
    def shortestSubstrings(self, arr: List[str]) -> List[str]:
        # w = arr[0]
        # print(w[1:3])
        missingStrings=[]
        result = [""] * len(arr)
        
        for n in range(len(arr)):
            w = arr[n] 
            missingStrings=[]
            for i in range(len(w)+1):
                for j in range(len(w)+1):
                    # print(f"n:{n}, w:{w}, i:{i}, j:{j}, w[i:j]:{w[i:j]}, len: {len(w[i:j])}")
                    if len(w[i:j]) >= 1 :
                        # print("len is >= 2")
                        if all([w[i:j] not in arr[a] for a in range(len(arr)) if a != n ]):
                            missingStrings.append(w[i:j])
            # print(sorted(missingStrings, key=lambda x: (len(x),x) ))
            if len(missingStrings) > 0:
                result[n] = sorted(missingStrings, key=lambda x: (len(x),x) )[0]
                
            
            # print(f"missingStrings:{missingStrings}")

        # print(f"result: {result}")
        return result
                       



        # arr = ["cab","ad","bad","c","ab"]
        # w = "ab"
        # print(sorted(arr, key=lambda x: (len(x),x) ))
        # # f = all([w not in a for a in arr if a != "cab" ])
        # # print(f)
        # n = 0
        # f = all([w not in arr[a] for a in range(len(arr)) if a != n ])
        # print(f)        


                    # for m in range(len(arr)):
                    #         print(f" m:{m}, n:{n}")
                    #         if m != n:
                    #             print(f"Is {w[i:j]} in {arr[m]}? ")
                    #             if w[i:j] in arr[m]:
                    #                 print(f"{w[i:j]} in {arr[m]}")
                    #                 # continue        
1466