Minimum Reverse Operations
You are given an integer n and an integer p representing an array arr of length n where all elements are set to 0, except position p which is set to 1. You are also given an integer array banned containing restricted positions.
Perform the following operation on arr:
- Reverse a subarray with size
kif the single1is not set to a position inbanned.
Return an integer array answer with n results where the i^th result is the minimum number of operations needed to bring the single 1 to position i in arr, or -1 if it is impossible.
Example 1
Input
n = 4, p = 0, banned = [1,2], k = 4Output
[0,-1,-1,1]Initially position 0 needs 0 operations, positions 1 and 2 are banned, and reversing the whole array moves the 1 to position 3 in one operation.
Example 2
Input
n = 5, p = 0, banned = [2,4], k = 3Output
[0,-1,-1,-1,-1]The 1 starts at position 0, but the only useful size-3 reversal would include banned position 2, so no other position can be reached.
Constraints
- 1 <= n <= 10^5
- 0 <= p <= n - 1
- 0 <= banned.length <= n - 1
- 0 <= banned[i] <= n - 1
- 1 <= k <= n
- banned[i] != p
- all values in banned are unique