Simple find all subarray approach
Intuition\nInstead of storing the char we are storing the indices of all subarray\nIt will be easier to find duplicate. if we store char it can be duplicate\n\n
# Intuition\nInstead of storing the char we are storing the indices of all subarray\nIt will be easier to find duplicate. if we store char it can be duplicate\n\n# Complexity\n- Time complexity:\nO(2^n * n^2)\n\n- Space complexity:\n(2^n * n)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>>allSubarr;\n    bool check(vector<int>&a,vector<int>&b){       \n        for(int i=0;i<a.size();i++)\n            for(int j=0;j<b.size();j++)\n                //if from the same index return false\n                if(a[i]==b[j]) return false;\n        return true;\n    }\n    bool isPalin(string &s,vector<int>&ans){\n        int a=0,b=ans.size()-1;\n        while(a<=b){\n            if(s[ans[a]]!=s[ans[b]]) return false;\n            a++;\n            b--;\n        }\n        return true;    \n    }\n    void findStr(string& s, vector<int>&temp, int idx){\n        //if at any point string is palindrome \n        //store it in ans\n        if(isPalin(s, temp)){\n            allSubarr.push_back(temp);\n        }\n        //idx is greater than length return\n        if(idx>=s.length()) return;\n        //take that char\n        temp.push_back(idx);\n        findStr(s, temp, idx+1);\n        //leave the char\n        temp.pop_back();\n        findStr(s, temp, idx+1);\n    }\n    int maxProduct(string s) {\n        int ans=0;\n        vector<int>temp;\n        //find all possible substring in allSubarr\n        findStr(s, temp, 0);\n        //check for all subarray if any 2 gives the max product value\n        for(int i=0; i<allSubarr.size(); i++){\n            for(int j=i+1; j<allSubarr.size(); j++){\n                //store the product\n                int x=(int)allSubarr[i].size()*allSubarr[j].size();\n                //check if selected 2 strings char are not from the same index\n                if(check(allSubarr[i], allSubarr[j])){\n                    //store max value of x\n                    ans=max(ans, x);\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']