Recursive Solution | Beginner Friendly | Java
Intuition\nIf we need to find all possible combinations, we should think of recursion\n\n# Approach\nIt is a classic pick or not pick problem. At every index, w
# Intuition\nIf we need to find all possible combinations, we should think of recursion\n\n# Approach\nIt is a classic pick or not pick problem. At every index, we\'ll either pick it or not pick, and once we reach the end of the input array, we\'ll check if our concatenated string is valid or not. If it is valid, we\'ll return the length, and store the maximum valid length with us.\n\n\n\n# Code\n```\nclass Solution {\n    public int maxLength(List<String> arr) {\n        return solve(0, arr, "");\n    }\n    public int solve(int index, List<String> arr, String input){\n        if (index == arr.size()){\n            if (isValid(input)){\n                return input.length();\n            }\n            return 0;\n        }\n        int take = solve(index+1, arr, input+arr.get(index));\n        int notTake = solve(index+1, arr, input);\n        return Math.max(take, notTake);\n    }\n    public boolean isValid(String s){\n        int [] freq = new int[26];\n        for(int i=0; i<s.length(); i++){\n            int val = s.charAt(i)-\'a\';\n            freq[val]++;\n            if (freq[val] > 1)  return false;\n        }\n        return true;\n    }\n}\n```
['Java']