2612. Minimum Reverse Operations
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<!-- 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 {\n public:\n  vector<int> minReverseOperations(int n, int p, vector<int>& banned, int k) {\n    const unordered_set<int> bannedSet{begin(banned), end(banned)};\n    vector<int> ans(n, -1);\n    // unseen[i] := unseen nums that are % 2 == i\n    vector<set<int>> unseen(2);\n\n    for (int num = 0; num < n; ++num)\n      if (num != p && !bannedSet.count(num))\n        unseen[num & 1].insert(num);\n\n    // Perform BFS from `p`.\n    queue<int> q{{p}};\n    ans[p] = 0;\n\n    while (!q.empty()) {\n      const int u = q.front();\n      q.pop();\n      const int lo = max(u - k + 1, k - 1 - u);\n      const int hi = min(u + k - 1, n - 1 - (u - (n - k)));\n      // Choose the correct set of nums.\n      set<int>& nums = unseen[lo & 1];\n      for (auto it = nums.lower_bound(lo); it != end(nums) && *it <= hi;) {\n        ans[*it] = ans[u] + 1;\n        q.push(*it);\n        it = nums.erase(it);\n      }\n    }\n\n    return ans;\n  }\n};\n\n```
['C++']