C++ BFS + Trees
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n$$O(nlogn)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> minReverseOperations(int n, int p, vector<int>& banned, int k) {\n        vector<int> ans(n, -1);\n        queue<int> q;\n        set<int> evens, odds;\n        set<int>* evens_odds = p % 2 == 0 ? &evens : &odds;\n        unordered_set<int> banned_set(banned.begin(), banned.end());\n        int ops = 1;\n\n        for (int i = 0; i < n + 2; ++i) {\n            if (!banned_set.contains(i)) {\n                (i % 2 == 0 ? evens : odds).insert(i);\n            }\n        }\n\n        ans[p] = 0;\n        q.push(p);\n        evens_odds->erase(p);\n\n        while (!q.empty()) {\n            if (k % 2 == 0) {\n                evens_odds = evens_odds == &evens ? &odds : &evens;\n            }\n\n            int cnt = q.size();\n\n            for (int i = 0; i < cnt; ++i) {\n                int pos1 = q.front();\n                int min_window_begin = max(0, pos1 - k + 1);\n                int max_window_begin = min(pos1, n - k);\n                int min_next_pos1 = k - 1 + 2 * min_window_begin - pos1;\n                int max_next_pos1 = k - 1 + 2 * max_window_begin - pos1;\n\n                q.pop();\n\n                auto it = evens_odds->lower_bound(min_next_pos1);\n\n                while (*it <= max_next_pos1) {\n                    ans[*it] = ops;\n                    q.push(*it);\n                    auto erase_it = it++;\n                    evens_odds->erase(erase_it);\n                }\n            }\n\n            ++ops;\n        }\n\n        return ans;\n    }\n};\n```
['C++']