Search
⌘K

Leetcode 1536. Minimum Swaps to Arrange a Binary Grid

Determine each row's rightmost 1 and treat those positions as requirements to place at or before their row index; greedily for each row i find the nearest row at or below i whose rightmost 1 ≤ i and bring it up with adjacent swaps, summing the distances (or return -1 if impossible).


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.