My Solution
\nclass Solution {\n public:\n  vector<int> minReverseOperations(const int n, const int p, const vector<int> &banned, const int k) {\n    bool banned_indices[n]
```\nclass Solution {\n public:\n  vector<int> minReverseOperations(const int n, const int p, const vector<int> &banned, const int k) {\n    bool banned_indices[n];\n    memset(banned_indices, 0, sizeof(banned_indices));\n    for (const int b : banned) {\n      banned_indices[b] = true;\n    }\n    \n    set<int> all_candidates[2];\n    for (int i = 0; i < n; ++i) {\n      if (!banned_indices[i] && i != p) {\n        all_candidates[i % 2].emplace(i);\n      }\n    }\n    vector<int> ret(n, -1);\n    queue<int> q({p});\n    int step = 0;\n    ret[p] = step;\n    while (!q.empty()) {\n      ++step;\n      for (size_t qs = q.size(); qs > 0; --qs) {\n        const int index = q.front();\n        q.pop();\n        const int lower = 2 * max(0, index - k + 1) + k - index - 1;\n        const int upper = 2 * (min(index + k, n) - k + 1) + k - index - 1;\n        set<int> &candidates = all_candidates[lower % 2];\n        for (auto itr = candidates.lower_bound(lower); itr != candidates.end() && *itr < upper; ) {\n          ret[*itr] = step;\n          q.emplace(*itr);\n          itr = candidates.erase(itr);\n        }\n      }\n    }\n    return ret;\n  }\n};\n```
[]