Maximum Product of Word Lengths LeetCode solution in Python
1class Solution:2def maxProduct(self, words: List[str]) -> int:3n = len(words)45bit_masks = [0] * n6lengths = [0] * n78for i in range(n):9for c in words[i]:10bit_masks[i] |= 1 << (ord(c) - ord("a")) # set the character bit11lengths[i] = len(words[i])1213max_val = 014for i in range(n):15for j in range(i + 1, n):16if not (bit_masks[i] & bit_masks[j]):17max_val = max(max_val, lengths[i] * lengths[j])1819return max_val