<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p>

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

<pre>
<strong>Input:</strong> words = [&quot;abcw&quot;,&quot;baz&quot;,&quot;foo&quot;,&quot;bar&quot;,&quot;xtfn&quot;,&quot;abcdef&quot;]
<strong>Output:</strong> 16
<strong>Explanation:</strong> The two words can be &quot;abcw&quot;, &quot;xtfn&quot;.
</pre>

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

<pre>
<strong>Input:</strong> words = [&quot;a&quot;,&quot;ab&quot;,&quot;abc&quot;,&quot;d&quot;,&quot;cd&quot;,&quot;bcd&quot;,&quot;abcd&quot;]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The two words can be &quot;ab&quot;, &quot;cd&quot;.
</pre>

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

<pre>
<strong>Input:</strong> words = [&quot;a&quot;,&quot;aa&quot;,&quot;aaa&quot;,&quot;aaaa&quot;]
<strong>Output:</strong> 0
<strong>Explanation:</strong> No such pair of words.
</pre>

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

<ul>
	<li><code>2 &lt;= words.length &lt;= 1000</code></li>
	<li><code>1 &lt;= words[i].length &lt;= 1000</code></li>
	<li><code>words[i]</code> consists only of lowercase English letters.</li>
</ul>

class Solution:
    def maxProduct(self, words: List[str]) -> int:
        # letterExist = [False] * 26
        # letterExist[0] = True
        # letterExist[1] = True

        # letterExist1[0] == letterExist2[0]?
        # letterExist1[1] == letterExist2[1]?
        # 26 times
        
        # bit1 = 10010101010.....0101
        # bit2 = 10001010101.....0101

        # 1 & 1 = 1
        # 1 & 0 = 0
        # 0 & 1 = 0
        # 0 & 0 = 0

        # 101
        # 010
        # 0
        
        # 110
        # 100
        # 100

        # 00000000 .... 000
        # mask = mask | 1 < 1
        # mask = (mask) | (1 < 2)
        # mask = (mask) | (1 < 3)

        # mask = (mask) | (1 < 2)
        # 00101010100
        # 00000000010
        # 00101010110

        # 00000000....00000
        # 00000000....00001
        # 00000000....00001

        # 00000000....00001
        # 00000000....00010
        # 00000000....00011

        # 00000000....00011
        # 00000000....00100
        # 00000000....00111

        # 1 | 1 = 1
        # 1 | 0 = 1
        # 0 | 1 = 1
        # 0 | 0 = 0

        # and or xor

        masks = []
        maxLen = 0
        for word in words:
            mask = 0
            for c in word:
                mask |= 1 << (ord(c) - ord('a'))
        
            masks.append(mask)
        
        for i in range(len(words)):
            for j in range(i + 1, len(words)):
                if masks[i] & masks[j] == 0:
                    maxLen = max(maxLen, len(words[i]) * len(words[j]))
        return maxLen
19300