Clean Java/JavaScript DFS solution
I think you can optimize a bit by adding memory to it. Time was limited during the contest, I didn\'t have time to optimized it.\n\n\nclass Solution {\n    priv
I think you can optimize a bit by adding memory to it. Time was limited during the contest, I didn\'t have time to optimized it.\n\n```\nclass Solution {\n    private int result = 0;\n\n    public int maxLength(List<String> arr) {\n        if (arr == null || arr.size() == 0) {\n            return 0;\n        }\n\n        dfs(arr, "", 0);\n\n        return result;\n    }\n\n    private void dfs(List<String> arr, String path, int idx) {\n        boolean isUniqueChar = isUniqueChars(path);\n        \n        if (isUniqueChar) {\n            result = Math.max(path.length(), result);\n        }\n\n        if (idx == arr.size() || !isUniqueChar) {\n            return;\n        }\n        \n        for (int i = idx; i < arr.size(); i++) {\n            dfs(arr, path + arr.get(i), i + 1);\n        }\n    }\n\n    private boolean isUniqueChars(String s) {\n        Set<Character> set = new HashSet<>();\n\n        for (char c : s.toCharArray()) {\n            if (set.contains(c)) {\n                return false;\n            }\n            set.add(c);\n        }\n        return true;\n    }\n}\n\n```\n\nJavaScript solution using memorization DFS from @jitendra8911 in the comment.\n\n```\nvar maxLength = function(arr) {\n    let maxLen = 0;\n    let listOfStrs = [];\n    arr = arr.filter(isUnique);\n    let mem = {};\n    maxLen = dfs(arr, "", 0, maxLen, mem);\n    \n    return maxLen;\n};\n\nfunction dfs(arr, path, i, maxLen, mem) {\n    if (mem[path]) return mem[path];\n    let pathIsUnique = isUnique(path);\n    if (pathIsUnique) {\n        maxLen = Math.max(path.length, maxLen);\n    } \n    if (i === arr.length || !pathIsUnique) {\n        mem[path] = maxLen;\n        return maxLen;\n    }\n    for (let j = i; j < arr.length; j++) {\n        maxLen = dfs(arr, path + arr[j], j + 1, maxLen, mem);\n    }\n\n\n    mem[path] = maxLen;\n    return maxLen;\n}\n\nfunction isUnique(str) {\n    const map = {}\n    for (let i = 0; i < str.length; i++) {\n        if (map[str[i]]) return false;\n        map[str[i]] = 1;\n    }\n    \n    return true;\n}\n\n\n```
[]