15 Lines of Code Easy Brutal Force Java Solution O(3^12 *12) Backtrack Solution
As long as I see the constraint is 0<len<12, I try to use brutal force which is backtrack.\nSo each position char can be either:\n1) pick by s1\n2) pick by s2\n
As long as I see the constraint is 0<len<12, I try to use brutal force which is backtrack.\nSo each position char can be either:\n1) pick by s1\n2) pick by s2\n3) pick by nobody.\n```\nclass Solution {\n    int max = 0;\n    public int maxProduct(String s) {\n        backtrack(s,0,"","");\n        return max;\n    }\n    \n    private void backtrack(String s, int i,String s1, String s2){\n        if(i == s.length()){\n            if(isValid(s1) && isValid(s2)){\n                max = Math.max(max, s1.length()*s2.length());\n            }\n            return;\n        }\n        backtrack(s,i+1,s1,s2);\n        backtrack(s,i+1,s1+s.charAt(i),s2);\n        backtrack(s,i+1,s1,s2+s.charAt(i));\n    }\n    private boolean isValid(String s){\n        if(s == null) return false;\n        for(int i = 0,j=s.length() - 1;i<j;i++,j--){\n            if(s.charAt(i) != s.charAt(j)) return false;\n        }\n        return true;\n    }\n}\n```
[]