#1239
Maximum Length of a Concatenated String with Unique Characters
specialist · 800 · lc medium +31 · verified · 54.7% accepted · 4,566 likes · top 47%
Description
You are given a string array arr. Select a subsequence of arr and concatenate its elements in order. The result is valid only if it contains no repeated characters.
Return the maximum length of any such valid concatenation.
A subsequence is derived by removing some or no elements from arr while keeping the original order.
Example 1:
Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All the valid concatenations are:
- ""
- "un"
- "iq"
- "ue"
- "uniq" ("un" + "iq")
- "ique" ("iq" + "ue")
Maximum length is 4.
Example 2:
Input: arr = ["cha","r","act","ers"]
Output: 6
Explanation: Possible longest valid concatenations are "chaers" ("cha" + "ers") and "acters" ("act" + "ers").
Example 3:
Input: arr = ["abcdefghijklmnopqrstuvwxyz"]
Output: 26
Explanation: The only string in arr has all 26 characters.
Code
1
2
3