DFS
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\n\n\n# Complexity\n-
# 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![image.png](https://assets.leetcode.com/users/images/bd132b55-c0eb-40dd-880b-f3fe66ea382b_1680419897.5582774.png)\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\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        const int pos_max = n - 1;\n        const int window_len = k;\n        const auto find_range = [&](const int pivot) -> std::pair<int, int> {\n            const int l1 = std::max(0, pivot - window_len + 1);\n            const int r1 = l1 + window_len - 1;\n            assert(r1 >= pivot);\n            const int lhs_diff = r1 - pivot;\n            const int lhs = l1 + lhs_diff;\n\n            const int r2 = std::min(pos_max, pivot + window_len - 1);\n            const int l2 = r2 - window_len + 1;\n            assert(l2 <= pivot);\n            const int rhs_diff = pivot - l2;\n            const int rhs = r2 - rhs_diff;\n            \n            return {lhs, rhs};\n        };\n\n        std::vector<bool> tbl_banned(n, false);\n        for (const int pos : banned) {\n            tbl_banned[pos] = true;\n        }\n        std::set<int> avail_pos_by_parity[2];\n        for (int pos = 0; pos < n; ++pos) {\n            if (tbl_banned[pos] || (pos == p)) {\n                continue;\n            }\n            avail_pos_by_parity[pos % 2].insert(pos);\n        }\n\n        std::vector<int> tbl_min_ops(n, -1);\n        tbl_min_ops[p] = 0;\n        std::queue<int> pos_ord;\n        pos_ord.push(p);\n        while (!pos_ord.empty()) {\n            const int target = pos_ord.front();\n            pos_ord.pop();\n            const auto [lhs, rhs] = find_range(target);\n            const int parity = \n                (window_len % 2 == 0) ? (1 - (target % 2)) : (target % 2);\n            auto &avail_pos = avail_pos_by_parity[parity];\n            auto it_init = avail_pos.lower_bound(lhs);\n            auto it_fini = avail_pos.upper_bound(rhs);\n            const int num_ops = tbl_min_ops[target];\n            assert(num_ops >= 0);\n            for (auto it = it_init; it != it_fini; ++it) {\n                tbl_min_ops[*it] = num_ops + 1;\n                pos_ord.push(*it);\n            }\n            avail_pos.erase(it_init, it_fini);\n        }\n        return tbl_min_ops;\n    }\n};\n```
['C++']