✔ C++ Beginner Friendly Recursive Solution ✔ Explained in Detail
Time Taken : 1732ms Faster than 28.54%\nNOTE : Please someone help me detrmine the time complexity of the given code\n\nAPPROACH :\n Generating all possible pal
**Time Taken : 1732ms Faster than 28.54%**\nNOTE : Please someone help me detrmine the time complexity of the given code\n\n**APPROACH :**\n* Generating all possible palindromic subsequence of the given string BUT instead of storing the string, I am storing the index of the subsequence thus formed into a vector.\n* For checking whether the subsequence is a PALINDROME or not , I can just use the index from the vector.\n* Storing the vector [ containing index of palindromic subsequence] into a 2D vector.\n* All possible cases are generated.\n* If two subsequences are valid and their product are greater than our maxProduct then we update our maxProduct.\n\n```\nclass Solution {\npublic:\n    vector<vector<int>>ar;\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(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 calc(string &s,vector<int>&ans,int i){\n        if(isPalin(s,ans))\n           ar.push_back(ans);\n        \n        if(i>=s.length()) return;\n        ans.push_back(i);\n        calc(s,ans,i+1);\n        ans.pop_back();\n        calc(s,ans,i+1);\n    }\n    int maxProduct(string s) {\n        int ans=0;\n        vector<int>a;\n        calc(s,a,0);\n        for(int i=0;i<ar.size();i++){\n            for(int j=i+1;j<ar.size();j++){              \n                int x=(int)ar[i].size()*ar[j].size();\n                if(x>ans&&check(ar[i],ar[j]))                   \n                    ans=x;\n            }\n        }\n        return ans;\n    }\n};\n```
['Backtracking', 'Recursion', 'C', 'C++']