Choose Five Words with 25 Distinct Letters
Problem statement
You are given distinct lowercase five-letter strings. Choose exactly five different strings so their combined 25 characters are all distinct.
Return the lexicographically smallest sorted array of five words among all valid choices. Return an empty array when no choice exists.
A word containing a repeated character can never be chosen.
Function
chooseFiveDisjointWords(words: String[]) → String[]Examples
Example 1
words = ["abcde","fghij","klmno","pqrst","uvwxy","zzzzz"]return = ["abcde","fghij","klmno","pqrst","uvwxy"]The first five words use 25 different letters.
Example 2
words = ["abcde","afghi","jklmn","opqrs","tuvwx"]return = []The only five words repeat a, so no choice works.
Example 3
words = []return = []Fewer than five words cannot form a choice.
Constraints
0 <= words.length <= 200.- Every word has length five, contains lowercase English letters, and words are distinct.