Problem
You are given an array of strings words. You may choose any subset of these strings and concatenate the chosen strings in any order.
Your goal is to produce a concatenated string that contains the maximum possible number of unique characters, subject to the constraint that no character appears more than once in the concatenation.
Return any valid concatenated string (or equivalently, any subset) that achieves the maximum number of unique characters.
Input
Output
-
A string
s
such that:
-
all characters in
s
are unique
-
|s|
is maximized among all valid choices
Examples
-
words = ["un","iq","ue"]
-
One optimal answer:
"uniq"
(length 4)
-
words = ["aa","bc","d"]
-
"aa"
cannot be used (has duplicate
a
), optimal answer could be
"bcd"
Constraints (typical interview assumptions)
-
1 <= words.length <= 16
(or small enough to allow backtracking)
-
Total characters across all words is moderate (e.g., <= 200)
-
Characters are lowercase English letters (state assumptions if asked)