C++ Backtracking Solution [EXPLAINED] [ACCEPTED}
APPROACH:\nBy seeing the constraints, it can be inferred that brute force approach should work fine.\nTo make disjoint subsequence we\'ll use 2 strings . Now, a
**APPROACH:**\nBy seeing the constraints, it can be inferred that brute force approach should work fine.\nTo make disjoint subsequence we\'ll use 2 strings . Now, at everry character i in string we have 3 choices:\n1) include that char in first string\n2) include that char in second string\n3) exclude that char from both strings\n\nto achieve this we\'ll use **backtracking** to generate all disjoint subsequences.\nNow of these subsequences , we consider only those which are pallindromic and leave the rest. For the pallindromic subsequence pair we calculate product eachtime and comapre with our ans calculated so far and update it if the latter product is greater.\n\n**NOTE :**\nMany code got TLE in same approach, that is because we have to pass every string by reference instead of pass by value, as in pass by value a copy of original string is made which takes time. So , to reduce that time and make ourcode faster we use backtracking instead of recursion  + pass by value.\n\n**CODE:**\nThe code is given below and is pretty much self explanatory.\n\n```\nlong long ans = 0;\n    \n    bool isPal(string &s)\n    {\n        int start=0, end = s.length()-1;\n        while(start < end)\n        {\n            if(s[start] != s[end]) return false;\n            start++; end--;\n        }\n        return true;\n    }\n    \n    void recur(string &s,int idx,string &s1,string &s2)\n    {\n        if(idx == s.size())\n        {\n            if(isPal(s1) and isPal(s2))\n            {\n                long long val =(int) s1.length() * s2.length();\n                ans = max(ans , val);\n            }\n            return;\n        }\n        \n        s1.push_back(s[idx]);\n        recur(s,idx+1,s1, s2);\n        s1.pop_back();\n        \n        s2.push_back(s[idx]);\n        recur(s,idx+1,s1,s2);\n        s2.pop_back();\n        \n        recur(s,idx+1,s1,s2);\n    }\n\t\n\tint maxProduct(string s) {\n        string s1="", s2 = "";\n        recur(s,0,s1,s2);\n        return ans;\n    }\n```\n\nDo upvote if it heps :)
['Backtracking', 'C']