Python || BFS, binary search || O(n log n)
Suppose we stand at i1, the widest range we can reach by one reverse is i1-k+1, i1-k+3, ..., i1+k-3, i1+k-1. The indices in the sequence are all even or all odd
1. Suppose we stand at `i1`, the widest range we can reach by one reverse is `i1-k+1`, `i1-k+3`, ..., `i1+k-3`, `i1+k-1`. The indices in the sequence are all even or all odd. \nBut we should be cautious when `i1 < k` or `i1 > n-k`. The starting index of the leftmost subarray containing `i1` is `max(0, i1-k+1)`, while the one of the rightmost subarray containing `i1` is `min(i1, n-k)`.\nFor a subarray containing `i1` with size `k`, say `[start:start+k]`, after reverse, `1` moved from `i1` to `i2 = 2*start-k-1-i1`.\nAssume the leftmost and rightmost indices we can reach are `le` and `ri`, respectively.\n2. During BFS, we would save indices not touched yet in `remain`. Because the possible indices in one step are all even/odd, we save even/odd indices seperately.\n3. To avoid TLE, use binary search to find the `intersection` of remaining indices(`remain[0]/remain[1]`) and `[le, ri]`.\n4. For each index `i2` in `intersection`, update `ans[i2]` and remove `i2` from `remain[0]/remain[1]`.\n```\nfrom collections import deque\nfrom bisect import bisect_left, bisect_right\n \nclass Solution:\n    def minReverseOperations(self, n: int, p: int, banned: List[int], k: int) -> List[int]:\n        ans = [-1]*n\n        ans[p] = 0\n        banned = set(banned)\n        remain_e = [i for i in range(n) if i not in banned and i != p and i&1 == 0]\n        remain_o = [i for i in range(n) if i not in banned and i != p and i&1 == 1]\n        remain = [remain_e, remain_o]\n        \n        cur = deque([p])\n        step = 1\n        while cur:\n            for _ in range(len(cur)):\n                i1 = cur.popleft()\n                lm, rm = max(0, i1-k+1), min(i1, n-k)\n                le = lm+lm+k-1-i1\n                ri = rm+rm+k-1-i1\n                i_l, i_r = bisect_left(remain[le&1], le), bisect_right(remain[le&1], ri)\n                intersection = remain[le&1][i_l:i_r]\n                for i2 in intersection:\n                    ans[i2] = step\n                    cur.append(i2)\n                    remain[le&1].pop(i_l)\n            step += 1\n        return ans
['Python3']