Python3 Solution
Intuition\nThis problem was hard to understand, and it has an O(K * N) issue that needs to be addressed.\n\n# Approach\nThe basic algorithm is a breadth-first s
# Intuition\nThis problem was hard to understand, and it has an $$O(K * N)$$ issue that needs to be addressed.\n\n# Approach\nThe basic algorithm is a breadth-first search of positions, where depth is a reversal operation.\n*   Avoid set lookups by marking `banned` positions with a `-2` reduces the constant coefficient speed-up. This is not enough to avoid a TLE, however.\n*   Every visited position has $$O(k)$$ potential target positions. On visiting a new position, the multiplicative cost can be avoided by updating `nextNode2s`, which originally points forward 2, to point beyond all target positions considered for that position.\n\n# Complexity\n- Time complexity: $$O(n + k)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution:\n    def minReverseOperations(self, n: int, p: int, banned: List[int], k: int) -> List[int]:\n        out = [-1] * n\n        # To speed up iterations, mark banned positions differently; remember to\n        # convert them to -1 at the end.\n        for node in banned:\n            out[node] = -2\n        # Perform reversals in level-based breadth-first order.\n        nodes = [p]\n        depth = 0\n        out[p] = depth\n        step = k - 1\n        \n        # TLEs occur when n is large, k is large, and not to many are banned,\n        # so that very O(N) points have O(N) possible post-reverse positions.\n        # These O(N) post-reverse positions are 2 apart, but each only needs\n        # to be visited once. We will nextNode2s dynamically to save work.\n        nextNode2s = [i + 2 for i in range(n)]  # might be out of range\n\n        while nodes:\n            depth += 1\n            newNodes = []\n            for node1 in nodes:\n                # The post-reverse positions are every other node between\n                # loNode2 and hiNode2, inclusive.\n                loReverseStart = max(node1 - step, 0)\n                hiReverseStart = min(node1, n - k) # Inclusive\n                loNode2 = 2 * loReverseStart + k - 1 - node1\n                hiNode2 = 2 * hiReverseStart + k - 1 - node1  # Inclusive\n                # We will exclude the entire range from future iterations\n                # by setting nextNode2s[node2] to hiNode2 + 2 for every\n                # visited node2.\n                postHiNode2 = hiNode2 + 2\n                node2 = loNode2\n                while node2 <= hiNode2:\n                    nextNode2 = nextNode2s[node2]\n                    nextNode2s[node2] = postHiNode2\n                    if node2 >= 0 and node2 < n and out[node2] == -1:\n                        newNodes.append(node2)\n                        out[node2] = depth\n                    node2 = nextNode2\n            nodes = newNodes\n            \n        # Mark all banned positions as -1 (see above).\n        for i in range(n):\n            if out[i] == -2:\n                out[i] = -1\n        return out\n        \n```
['Python3']