Maximum Length of a Concatenated String with Unique Characters - Problem
You are given an array of strings arr. A string s is formed by the concatenation of a subsequence of arr that has unique characters.
Return the maximum possible length of s.
A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
Input & Output
Example 1 — Basic Concatenation
$
Input:
arr = ["un","iq","ue"]
›
Output:
4
💡 Note:
We can concatenate "un" + "iq" = "uniq" which has 4 unique characters. Other combinations like "unue" have duplicate 'u', so length 4 is maximum.
Example 2 — All Single Characters
$
Input:
arr = ["cha","r","act","ers"]
›
Output:
6
💡 Note:
We can concatenate "cha" + "r" + "t" (from "act") is not valid since we must take whole strings. Best combination is "cha" + "ers" = "chaers" but has duplicate 'a'. Actually "r" + "act" = "ract" (5 chars) or "cha" + "r" = "char" (4 chars). Wait, we take whole strings: "r" + "act" = "ract" has unique chars, length 4.
Example 3 — No Valid Combination
$
Input:
arr = ["aa","bb"]
›
Output:
0
💡 Note:
Each string itself contains duplicate characters ("aa" has two 'a's, "bb" has two 'b's), so we cannot use any string. Maximum length is 0.
Constraints
- 1 ≤ arr.length ≤ 16
- 1 ≤ arr[i].length ≤ 26
- arr[i] contains only lowercase English letters
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array of strings: ["un", "iq", "ue"]
2
Process
Find valid subsequence combinations with unique chars
3
Output
Maximum possible length: 4 from "uniq"
Key Takeaway
🎯 Key Insight: Use backtracking to explore all valid subsequence combinations while efficiently checking character uniqueness with bitmasks
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code