Ctrl K

Words With No Shared Letters

Medium
You get a list of words terms made of lowercase English letters. Choose two different words (by position in the list) that have no letter in common and multiply their lengths. Return the largest such product. If no pair qualifies, return 0.
Example 1
terms=["plum", "kiwi", "pear", "fig", "lychee"] → 24

"kiwi" and "pear" share no letters: 4 · 4 = 16. "lychee" (6 letters) and "kiwi" are disjoint too, and 6 · 4 = 24 is better, so that is the answer.

Example 2
terms=["ab", "ba", "a"] → 0

Any two words share the letter "a", so no pair works and the answer is 0.

Constraints
  • 2 ≤ len(terms) ≤ 1000
  • 1 ≤ len(terms[i]) ≤ 1000
  • Words consist of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPalindrome After a Few Fixes MediumOne New Letter MediumCode Lookup in a Bit String MediumShortest Unambiguous Shorthand HardAssembling Fragments Hard
loading Python…
Input
terms=["plum", "kiwi", "pear", "fig", "lychee"]
Expected
24

Run checks the first 3 tests in your browser. Submit checks all 69 tests on the server, hidden ones included.