O(n) using BFS with two queues and limiting min, max
Main Idea\n+ BFS with two queues using rotating 1\n+ k=1: ans[i] = (1) -1 with i!=p (2) 0 with i=p\n+ k>0:\n\nq1 <- [p] with p is initial value 1\nans[i] = {-1 
# Main Idea\n+ BFS with two queues using rotating 1\n+ k=1: ans[i] = (1) -1 with i!=p (2) 0 with i=p\n+ k>0:\n```\nq1 <- [p] with p is initial value 1\nans[i] = {-1 with i!=p and 0 with i=p}\nwhile q1 not empty:\n  \n  # optimization for complexity\n  tt = [calculating [vmin, vmax] for all u in q1]\n  sorted(tt) -> get vmin, vmax in tt\n  \n  # bfs two queues\n  q2 = []\n  for v in [vmin, vmax] with step=2:\n    if check[v] is False and v not in banned:\n      check[v] = true\n      ans[v] = ans[u] + 1\n      q2.append(v)\n  q1 = q2\n```\n\n# Examples\n```\nExample 1: n = 4, p = 0, banned = [1, 2], k = 4\n\n--- q1 = [0] ---\n+ [vmin, vmax] = [3, 3]\n+ q2 = [3]\n+ chk = [True, False, False, True]\n\n--- q1 = [3] ---\n+ [vmin, vmax] = [0, 0]\n+ q2 = []\n+ chk = [True, False, False, True]\n\n--- ans ---\nans = [0, -1, -1, 1]\n----------\n\nExample 2: n = 5, p = 0, banned = [2, 4], k = 3\n\n--- q1 = [0] ---\n+ [vmin, vmax] = [2, 2]\n+ q2 = []\n+ chk = [True, False, False, False, False]\n\n--- ans ---\nans = [0, -1, -1, -1, -1]\n----------\n\nExample 3: n = 6, p = 2, banned = [], k = 4\n\n--- q1 = [2] ---\n+ [vmin, vmax] = [1, 5]\n+ q2 = [1, 3, 5]\n+ chk = [False, True, True, True, False, True]\n\n--- q1 = [1, 3, 5] ---\n+ [vmin, vmax] = [0, 4]\n+ q2 = [0, 4]\n+ chk = [True, True, True, True, True, True]\n\n--- q1 = [0, 4] ---\n+ [vmin, vmax] = [1, 3]\n+ q2 = []\n+ chk = [True, True, True, True, True, True]\n\n--- ans ---\nans = [2, 1, 0, 1, 2, 1]\n----------\n```\n\n# Code\n```\n# DEBUG = True\nD = lambda fn: fn() if globals().get("DEBUG", False) else lambda fn: ()\n\nclass Solution:\n    def minReverseOperations(self, n: int, p: int, banned: List[int], k: int) -> List[int]:\n        D(lambda: print(f\'Example: n = {n}, p = {p}, banned = {banned}, k = {k}\\n\'))\n        ans = [-1] * n\n        ans[p] = 0\n        if k>1:\n            avoid = [0] * n\n            for i in range(len(banned)):\n                avoid[banned[i]] = 1\n            chk = [False] * n\n            chk[p] = True\n            q1 = [p]\n            cnt = 1\n            v_chan = [-1, -1]\n            v_le = [-1, -1]\n            \n            while len(q1)>0:\n                D(lambda: print(f\'--- q1 = {q1} ---\'))\n                q2 = []\n                \n                tt = []\n                for u in q1:\n                    step_min = max(0, u - k + 1) - (u - k + 1)\n                    step_max = (k-1) - max(0, (u + k - 1) - min(n - 1, u + k - 1))\n                    v_min = (u - k + 1) + 2 * step_min\n                    v_max = (u - k + 1) + 2 * step_max\n                    tt.append(v_min)\n                    tt.append(v_max)\n                tt = sorted(tt)   \n                v_min, v_max = tt[0], tt[-1]\n                D(lambda: print(f\'+ [vmin, vmax] = [{v_min}, {v_max}]\'))\n                \n                for v in range(v_min, v_max+1, 2):\n                    if chk[v] is False and avoid[v]==0:\n                        chk[v] = True\n                        ans[v] = ans[u] + 1\n                        q2.append(v)\n                D(lambda: print(f"+ q2 = {q2}"))\n                D(lambda: print(f"+ chk = {chk}\\n"))\n                q1 = q2\n        D(lambda: print(f\'--- ans ---\\nans = {ans}\\n----------\\n\\n\'))\n        return ans\n```
['Breadth-First Search', 'Python3']