Doubly linked list, python
\n# Code\n\nclass Solution:\n    def minReverseOperations(self, n: int, p: int, banned: List[int], k: int) -> List[int]:\n        right = [(i+2) % (n+4) for i i
\n# Code\n```\nclass Solution:\n    def minReverseOperations(self, n: int, p: int, banned: List[int], k: int) -> List[int]:\n        right = [(i+2) % (n+4) for i in range(n+4)]\n        left = [(i-2) for i in range(n+4)]\n        distance = [-1] * n\n        q = collections.deque(maxlen=n)\n\n        def first(i):\n            j = right[i]\n            if left[j] == i:\n                return i\n            else:\n                right[i] = first(j)\n                return right[i]\n\n        def drop(i):\n            left[right[i]], right[left[i]] = left[i], right[i]\n\n        def set_distance(i, d):\n            distance[i] = d\n            q.append(i)\n            drop(i)\n\n        for i in banned:\n            drop(i)\n\n        set_distance(p, 0)\n        while q:\n            i0 = q.popleft()\n            s0 = abs(i0 - (k - 1))\n            i = first(s0)\n            if i < n:\n                d = distance[i0] + 1\n                s1 = min(i0+k-1, 2*n-k-1-i0)\n                while i <= s1:\n                    set_distance(i, d)\n                    i = right[i]\n\n\n        return distance\n\n```
['Python3']