# Get the Maximum Length of a Concatenated String with Unique Characters in Python

## The problem

Given an array of strings `arr`. String `s` is a concatenation of a sub-sequence of `arr` which have unique characters.

Return the maximum possible length of `s`.

## Example test-cases

Example 1:

```Input: arr = ["un","iq","ue"]
Output: 4
Explanation: All possible concatenations are "","un","iq","ue","uniq" and "ique".
Maximum length is 4.
```

Example 2:

```Input: arr = ["cha","r","act","ers"]
Output: 6
Explanation: Possible solutions are "chaers" and "acters".
```

Example 3:

```Input: arr = ["abcdefghijklmnopqrstuvwxyz"]
Output: 26```

## Constraints

• `1 <= arr.length <= 16`
• `1 <= arr[i].length <= 26`
• `arr[i]` contains only lower case English letters.

## How to write the code

```.wp-block-code {
border: 0;
}

.wp-block-code > div {
overflow: auto;
}

.shcb-language {
border: 0;
clip: rect(1px, 1px, 1px, 1px);
-webkit-clip-path: inset(50%);
clip-path: inset(50%);
height: 1px;
margin: -1px;
overflow: hidden;
position: absolute;
width: 1px;
word-wrap: normal;
word-break: normal;
}

.hljs {
box-sizing: border-box;
}

.hljs.shcb-code-table {
display: table;
width: 100%;
}

.hljs.shcb-code-table > .shcb-loc {
color: inherit;
display: table-row;
width: 100%;
}

.hljs.shcb-code-table .shcb-loc > span {
display: table-cell;
}

.wp-block-code code.hljs:not(.shcb-wrap-lines) {
white-space: pre;
}

.wp-block-code code.hljs.shcb-wrap-lines {
white-space: pre-wrap;
}

.hljs.shcb-line-numbers {
border-spacing: 0;
counter-reset: line;
}

.hljs.shcb-line-numbers > .shcb-loc {
counter-increment: line;
}

.hljs.shcb-line-numbers .shcb-loc > span {
}

.hljs.shcb-line-numbers .shcb-loc::before {
border-right: 1px solid #ddd;
content: counter(line);
display: table-cell;
text-align: right;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
white-space: nowrap;
width: 1%;
}
```def maxLength(arr: List[str]) -> int:
result = [float('-inf')]

unique_char("", arr, , result)

if not result[] == float('-inf'):
return result[]
return

def unique_char(cur, arr, index, result):
# End of the array
if index == len(arr):
return

# Iterating from the current word to the end of the array
for index in range(index,len(arr)):

# If current word + next word have all unique characters
if len(set(cur + arr[index])) == len(list(cur + arr[index])):
# Compare the actual lenth with the previous max
result[] = max(result[],len(cur + arr[index]))
# Make a new call with concatenate words
unique_char(cur + arr[index], arr, index + 1,result)
```Code language: Python (python)```

Subscribe
Notify of