Description
Given a string array words, return the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. If no such two words exist, return 0.
Example 1:
1 | Input: words = ["abcw","baz","foo","bar","xtfn","abcdef"] |
Example 2:
1 | Input: words = ["a","ab","abc","d","cd","bcd","abcd"] |
Example 3:
1 | Input: words = ["a","aa","aaa","aaaa"] |
Constraints:
1 | 2 <= words.length <= 1000 |
Solution
- create a list called s to store all the individual letter of each word
- using two for loops to compare each two words in the list, if there is no common letter, update the answer
1 | # O(n^2) time | O(n) space |