#2612

Minimum Reverse Operations

grandmaster · 2275 · lc hard +32 · 16.7% accepted · 255 likes · top 1%

Description

You have a length-n array of zeros except position p which holds 1. Positions in banned cannot hold the 1 after an operation. An operation reverses any length-k subarray (only when the 1 is not in a banned position after the reversal). Return an array where the i-th entry is the minimum operations to move the 1 to position i, or -1 if impossible.

Code

1
2
3