All about DS optimisations.
\nclass Solution {\npublic:\n    vector<int> minReverseOperations(int n, int p, vector<int>& banned, int k) {\n        set<int> avail[2];\n        for(int i = 0
```\nclass Solution {\npublic:\n    vector<int> minReverseOperations(int n, int p, vector<int>& banned, int k) {\n        set<int> avail[2];\n        for(int i = 0; i < n; i++){\n            avail[i%2].insert(i);\n        }\n        for(int x: banned) avail[x%2].erase(x);\n        vector<int> ans(n, -1);\n        ans[p] = 0;\n        queue<int> q;\n        q.push(p);\n        avail[p%2].erase(p);\n        int x, d, s, e, i;\n        set<int>:: iterator it, is, ie;\n        while(!q.empty()){\n            x = q.front();\n            q.pop();\n            d = ans[x] + 1;\n            s = max(x - k + 1, k - x - 1);\n            e = min(x + k - 1, 2*n - k - x);\n            i = s%2;\n            it = avail[i].lower_bound(s);\n            is = it;\n            ie = avail[i].end();\n            while(it != avail[i].end()){\n                if(*it > e) {\n                    ie = it;\n                    break;\n                }\n                q.push(*it);\n                ans[*it] = d;\n                it++;\n            }\n            avail[i].erase(is, ie);  \n        }\n        return ans;\n    }\n};\n```
['Breadth-First Search']