backtracking approach | 2 ways
Code\njava []\n    public int maxLength(List<String> arr) {\n        int select[] = new int[26];\n        return solve(0,0,select,arr);\n    }\n    int solve(in
# Code\n```java []\n    public int maxLength(List<String> arr) {\n        int select[] = new int[26];\n        return solve(0,0,select,arr);\n    }\n    int solve(int p,int len,int select[],List<String> arr){\n        if(p==arr.size()) return len;\n        if(isValid(arr.get(p),select)){\n            String str =arr.get(p);\n            len+=str.length();\n            markOne(str,select);\n            int l1= solve(p+1,len,select,arr);\n            markZero(str,select);\n            len-=str.length();\n            int l2=solve(p+1,len,select,arr);\n            return Math.max(l1,l2);\n        }else return solve(p+1,len,select,arr);\n    }\n    void markOne(String s,int select[]){\n        for(char c:s.toCharArray()) select[c-\'a\']=1;\n    }\n    void markZero(String s,int select[]){\n        for(char v:s.toCharArray()) select[v-\'a\']=0;\n    }\n    boolean isValid(String s,int fre[]){\n        if(s.length()>26) return false;\n        boolean c[] = new boolean[26];\n        for(char ch:s.toCharArray()){\n            if(c[ch-\'a\']) return false;\n            if(fre[ch-\'a\']==1) return false;\n            c[ch-\'a\']=true;\n        }return true;\n    }\n```\n```java [2]\npublic int maxLength1(List<String> arr) {\n        HashSet<String> A = new HashSet<String>();\n        A.add("");\n        for (String s : arr) {\n            if (!isUnique(s)) continue;\n            HashSet<String> t = new HashSet<String>();\n            for (String c : A) {\n                String temp = c + s;\n                if (isUnique(temp)) t.add(temp);\n            }\n            A.addAll(t);\n        }\n       return A.stream().max(Comparator.comparing(String::length)).get().length();\n    }\n boolean isUnique(String st) {\n        if (st.length() > 26) return false;\n        boolean A[] = new boolean[26];\n        for(char c:st.toCharArray()){\n            if(A[c-\'a\']) return false;\n            A[c-\'a\']=true;\n        }return true;\n    }\n```\n\n\n# Complexity\n- Time complexity: o(n*k)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:o(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n![meme2.png](https://assets.leetcode.com/users/images/c6d0d334-f51e-4eaa-bd6b-4e3dcb34d33c_1679716889.1266408.png)\n
['Backtracking', 'Python', 'C++', 'Java']