BFS + disjoint set union
Main intuition is to  use BFS to record the time of first discovery of a node. Given a root node, we can determine which nodes will be reached in the next step 
Main intuition is to  use BFS to record the time of first discovery of a node. Given a root node, we can determine which nodes will be reached in the next step fairly easily; the main challenge is to make sure that, at each step, only non-visited nodes are explored, otherwise the time complexity will be quadratic in the size of the input. I used DSU to achieve this goal; in my implementation, each time a node is explored, we set its parent to be the node two positions on the right (two because, when reversing arrays, we can only visit nodes that are two positions apart from each other). \n\nOverall, space complexity is `O(n)`. Time complexity is `O(n*log(n))`, which could be optimized to `O(n)` by optimizing the merge operation in the DSU.\n\n```\nclass Solution {\n    \n    vector<int> parents;\n    \npublic:\n    vector<int> minReverseOperations(int n, int p, vector<int>& banned, int k) {\n        vector<int> ans(n, -1);\n        parents = vector<int>(n+1, 0);\n        iota(parents.begin(), parents.end(), 0);\n                        \n        for (auto idx: banned) {\n            ans[idx] = -1; \n            parents[idx] = min(n, idx + 2);\n        }\n        \n        ans[p] = 0; parents[p] = min(p + 2, n);\n        \n        int cnt = 0;\n        queue<int> q; q.push(p);\n        \n        while (q.size()) {\n            int l = q.size();\n            for (int i = 0; i < l; ++i) {\n                int root = q.front(); q.pop();\n                auto [lBound, rBound] = computeBounds(n, k, root);\n                \n                for (int child = findParent(lBound); child <= rBound; child = findParent(child)) {\n                    ans[child] = cnt + 1; \n                    parents[child] = min(child + 2, n); \n                    q.push(child);                    \n                }\n            }\n            \n            cnt += 1;\n        }\n        \n        \n        return ans;\n    }\n    \n    pair<int, int> computeBounds(int n, int k, int pos) {        \n        int rEnd = max(pos, k-1);\n        int ansL = rEnd - (k-1) + (rEnd - pos);\n        \n        int lEnd = min(pos, n - k);\n        int ansR = lEnd + (k-1) - (pos - lEnd);\n\n        return {ansL, ansR};\n    }\n    \n    int findParent(int root) {\n        if (parents[root] != root) {\n            parents[root] = findParent(parents[root]);\n        }\n        \n        return parents[root];\n    }\n};\n```
[]