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 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.
class Solution:
    def maxLength(self, arr: List[str]) -> int:
        res = 0
        def dfs(n, s, l, cur):
            nonlocal res
            if n == l:
                if len(set(cur)) == len(cur):
                    res = max(res, len(cur))
                return
            for i in range(s, len(arr)):
                new_cur = cur + arr[i]
                if len(set(cur)) != len(cur):
                    return
                dfs(n, i+1, l+1, new_cur)
        for i in range(len(arr)+1):
            dfs(i, 0, 0, '')
        return res

class Solution:
    def maxLength(self, arr: List[str]) -> int:
        res = 0
        def dfs(n, s, l, cur):
            nonlocal res
            if n == l:
                if len(set(cur)) == len(cur):
                    res = max(res, len(cur))
                return
            for i in range(s, len(arr)):
                new_cur = cur + arr[i]
                if len(set(cur)) != len(cur):
                    return
                dfs(n, i+1, l+1, new_cur)
        for i in range(len(arr)+1):
            dfs(i, 0, 0, '')
        return res
