2612. Minimum Reverse Operations
You are given an integer
n
and an integerp
in the range[0, n - 1]
. Representing a 0-indexed arrayarr
of lengthn
where all positions are set to0
‘s, except positionp
which is set to1
.You are also given an integer array
banned
containing some positions from the array. For the i**th** position inbanned
,arr[banned[i]] = 0
, andbanned[i] != p
.You can perform multiple operations on
arr
. In an operation, you can choose a subarray with sizek
and reverse the subarray. However, the1
inarr
should never go to any of the positions inbanned
. In other words, after each operationarr[banned[i]]
remains0
.Return an array
ans
where for eachi
from[0, n - 1]
,ans[i]
is the minimum number of reverse operations needed to bring the1
to positioni
in arr, or-1
if it is impossible.
- A subarray is a contiguous non-empty sequence of elements within an array.
- The values of
ans[i]
are independent for alli
‘s.- The reverse of an array is an array containing the values in reverse order.
1 | class Solution { |