C++
\nclass Solution {\npublic:\n    vector<int> minReverseOperations(int n, int p, vector<int>& banned, int k) {\n        set<int>odd;\n        set<int>even;\n    
```\nclass Solution {\npublic:\n    vector<int> minReverseOperations(int n, int p, vector<int>& banned, int k) {\n        set<int>odd;\n        set<int>even;\n        vector<int>ret(n, -1);\n        set<int>banned_set(banned.begin(), banned.end());\n        \n        for(int i = 0; i < n; i++){\n            if(banned_set.find(i) != banned_set.end())\n                continue;\n            if(i == p)\n                continue;\n            if(i%2)\n                odd.insert(i);\n            else\n                even.insert(i);\n        }\n        \n        queue<int>q;\n        q.push(p);\n        ret[p] = 0;\n        int step = 0;\n        while(!q.empty()){\n            step++;\n            int len = q.size();\n            for(int i = 0; i < len; i++){\n                int idx = q.front();\n                q.pop();\n                int L0 = max(0, idx-k+1);\n                //j0 is next possible 1 position\n                int j0 = (2*L0+k-1)-idx;\n                \n                int L1 = min(n-k, idx);                \n                int j1 = (2*L1+k-1)-idx;\n                \n                set<int>*s;\n                if(j0 % 2 == 0)\n                    s = &even;\n                else\n                    s = &odd;\n                auto iter = s->lower_bound(j0);\n                while (iter!=s->end() && *iter<=j1)\n                {\n                    ret[*iter] = step;\n                    q.push(*iter);\n                    iter++;\n                    s->erase(prev(iter));\n                }\n            }\n        }\n        return ret;\n    }\n};\n```\n
[]