Largest Product of Length
Given a dictionary containing many words, find the largest product of two words’ lengths, such that the two words do not share any common characters.
Assumptions
The words only contains characters of 'a' to 'z'
The dictionary is not null and does not contains null string, and has at least two strings
If there is no such pair of words, just return 0
Examples
dictionary = [“abcde”, “abcd”, “ade”, “xy”], the largest product is 5 * 2 = 10 (by choosing “abcde” and “xy”)
Solution: try every comb with bitMask to check for dup characters
TC: O(N^2) check every i * j combination
SC: O(N) Hashmap
Last updated
Was this helpful?