C++ | BFS
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nC : cheked position\n0 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nC : cheked position\n0 : not cheked yet\nX : current position\n\noveral status shape would be below.\n\n0 0 0 C C C C 0 0 0 X 0 0 0 C C C C 0 0 0 0 0 \n\nin this case, I can check for new positions from X like below.\n\n---> CCCC <--- X ---> CCCCC <---\n\n** four directions\n** if meet checked postion then break\n\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        vector<int> ans(n, -1);        \n        ans[p] = 0;\n        if(k == 1) return ans;\n\n        vector<char>visit(n, 0);\n        vector<char>ban(n, 0);        \n        queue<int> Q;\n\n        for(int num : banned) ban[num] = 1;\n        visit[p] = 1;\n        Q.push(p);\n        int cur;\n        int s, e, loc;\n        while(!Q.empty()) {            \n            cur = Q.front();\n            Q.pop();\n\n            // right, outside -> inside\n            s = cur;\n            e = cur + k - 1;\n            if(e >= n) {\n                s -= e - n + 1;\n                e = n - 1;                \n            }\n          \n            while(s >= 0 && cur - s < e - cur) {\n                loc = e + s - cur;                \n                if(ban[loc]) {\n                    --s, --e;\n                    continue;\n                }                \n                if(visit[loc]) break;                \n                visit[loc] = 1;\n                ans[loc] = ans[cur] + 1;\n                Q.push(loc);\n                --s, --e;\n            }\n\n            // left, outside -> inside\n            s = cur - k + 1;\n            e = cur;\n            if(s < 0) {\n                e -= s;\n                s = 0;\n            }\n\n            while(e < n && cur - s > e - cur) {\n                loc = e + s - cur;\n                if(ban[loc]) {\n                    ++s, ++e;\n                    continue;\n                }            \n                if(visit[loc]) break;\n                visit[loc] = 1;\n                ans[loc] = ans[cur] + 1;\n                Q.push(loc);\n                ++s, ++e;\n            }\n\n            // right, inside -> outside\n            s = cur - (k - 1) / 2;\n            e = cur + k / 2;\n            if(k&1) {\n                ++s, ++e;\n            }\n            \n            if(e >= n) {\n                s -= e - n + 1;\n                e = n - 1;                \n            }\n            if(s < 0) {\n                e -= s;\n                s = 0;\n            }\n\n           \n            while(s <= cur && e < n && cur - s < e - cur) {\n                loc = e + s - cur;                \n                if(ban[loc]) {\n                    ++s, ++e;\n                    continue;\n                }                \n                if(visit[loc]) break;                \n                visit[loc] = 1;\n                ans[loc] = ans[cur] + 1;\n                Q.push(loc);\n                ++s, ++e;\n            }\n\n            // left, inside -> outside\n            s = cur - (k - 1) / 2 - 1;\n            e = cur + k / 2 - 1;\n            if(e >= n) {\n                s -= e - n + 1;\n                e = n - 1;                \n            }\n            if(s < 0) {\n                e -= s;\n                s = 0;\n            }\n\n            while(e >= cur && s >= 0 && cur - s > e - cur) {\n                loc = e + s - cur;\n                if(ban[loc]) {\n                    --s, --e;\n                    continue;\n                }            \n                if(visit[loc]) break;\n                visit[loc] = 1;\n                ans[loc] = ans[cur] + 1;\n                Q.push(loc);\n                --s, --e;\n            }\n        }\n\n        return ans;\n    }       \n};\n\n\n\n\n\n\n\n```
['C++']