Problem · Array
Maximum Unique-Character Word Subset
Learn this problemProblem statement
Given an array of lowercase English words, choose a subset whose concatenation contains no repeated character. Return the maximum possible length of such a concatenation.
A word that repeats a character inside itself cannot be selected. The order of selected words does not affect validity, and the empty subset is allowed. Return only the maximum length, not the selected subset.
Function
maxUniqueCharacterSubsetLength(words: String[]) → intExamples
Example 1
words = ["un","iq","ue"]return = 4Selecting un and iq produces four distinct characters. Adding ue would repeat u.
Example 2
words = ["cha","r","act","ers"]return = 6Selecting cha and ers produces the six distinct characters in chaers.
Example 3
words = ["aa","bc"]return = 2The word aa is invalid because it repeats a internally. Selecting only bc gives length 2.
Constraints
0 <= words.length <= 16.1 <= words[i].length <= 26.- Every word contains only lowercase English letters.