# 1239. Maximum Length of a Concatenated String with Unique Characters

### Description

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`.

### Constraints

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

### Approach

### Links

* [Binarysearch](https://binarysearch.com/problems/Concatenated-String-of-Unique-Count)
* GeeksforGeeks
* [Leetcode](https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters/)
* ProgramCreek
* YouTube

### **Examples**

{% tabs %}
{% tab title="Example 1" %}
**Input:** arr = \["un", "iq", "ue"]

**Output:** 4

**Explanation:** All possible concatenations are "", "un", "iq", "ue", "uniq" and "ique".

Maximum length is 4.
{% endtab %}

{% tab title="Example 2" %}
**Input:** arr = \["cha", "r", "act", "ers"]

**Output:** 6

**Explanation:** Possible solutions are "chaers" and "acters".
{% endtab %}

{% tab title="Example 3" %}
**Input:** arr = \["abcdefghijklmnopqrstuvwxyz"]

**Output:** 26
{% endtab %}
{% endtabs %}

### **Solutions**

{% tabs %}
{% tab title="Solution 1" %}

```java
/**
 * Time complexity : 
 * Space complexity : 
 */

class Solution {
    private int maxLen = 0;
    
    public int maxLength(List<String> words) {
        if(words != null && !words.isEmpty()) {
            dfs(words, 0, "");
        }
        return maxLen;
    }
    
    private void dfs(List<String> words, int index, String word) {
        if(index > words.size()) {
            return;
        }
        
        if(isUniqueCharsInStr(word)) {
            maxLen = Math.max(maxLen, word.length());
        } else {
            return;
        }
        
        for(int i = index; i < words.size(); i++) {
            dfs(words, i+1, word + words.get(i));
        }
    }
    
    private boolean isUniqueCharsInStr(String s) {
        if(s.length() < 2) {
            return true;
        }
        Set<Character> set = new HashSet();
        for(char ch: s.toCharArray()) {
            if(set.contains(ch)) {
                return false;
            }
            set.add(ch);
        }
        return true;
    }
}
```

{% endtab %}
{% endtabs %}

### **Follow up**

*


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://code-snippets.hbamithkumara.com/leetcode/problems/1201-1300/maximum-length-of-a-concatenated-string-with-unique-characters.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
