Maximum Product of Word Lengths
Solution Code
class Solution:
def maxProduct(self, words: List[str]) -> int:
mask_to_len = {}
for word in words:
mask = 0
for char in word:
mask |= 1 << (ord(char) - 97)
# Only keep the maximum length for this mask
mask_to_len[mask] = max(mask_to_len.get(mask, 0), len(word))Time Complexity
O(N L + M^2)
Space Complexity
O(M)

