c++ brute force with memoization solution
\nclass Solution {\npublic:\n    void f(string str, int depth, int& small, int& big, unordered_set<string>& dp) {\n        //cout<<str<<endl; \n        const in
```\nclass Solution {\npublic:\n    void f(string str, int depth, int& small, int& big, unordered_set<string>& dp) {\n        //cout<<str<<endl; \n        const int n = str.size();\n        for(int i = 0;i<n/2;i++) {\n            if(str[i] == \'1\' && str[str.size()-1-i] == \'1\') {\n                small = min(small,depth);\n                big = max(big,depth);\n                return;\n            }\n        }\n        if(dp.count(str)) {\n            return; \n        }\n        const int total = (1<<(n/2)) - 1; \n        for(int i = 0;i<=total;i++) {\n            string a;\n            string b; \n            bool valid = true; \n            for(int j = 0;j<n/2;j++) {\n                // 1 left win \n                // 0 right win\n                if(i&(1<<j) && str[str.size()-j-1] == \'1\') {\n                    valid = false; \n                    break;\n                } \n                if(!(i&(1<<j)) && str[j] == \'1\') {\n                    valid = false; \n                    break; \n                }\n                if(i&(1<<j)) {\n                    a.push_back(str[j]);\n                } else {\n                    b.push_back(str[str.size()-j-1]);\n                }\n            }\n            if(!valid) {\n                continue; \n            }\n            string tmp; \n            reverse(b.begin(),b.end());\n            if(str.size() % 2 == 1) {\n                tmp = a + string(1,str[str.size()/2]) + b; \n            } else {\n                tmp = a + b; \n            }\n            f(tmp,depth+1,small,big,dp);\n        }\n        dp.insert(str);\n    }\n    vector<int> earliestAndLatest(int n, int fp, int sp) {\n        string str; \n        for(int i = 1;i<=n;i++) {\n            if(i == fp || i == sp) {\n                str.push_back(\'1\');\n            } else {\n                str.push_back(\'0\');\n            }\n        }\n        unordered_set<string> dp; \n        //cout<<str<<endl;\n        int big = 0; \n        int small = INT_MAX; \n        f(str,1,small,big,dp);\n        return {small,big};\n    }\n};\n```
[]