Problem 2459 · Medium

Sort Array by Moving Items to Empty Space

Split the moves into cycles of the target mapping: a cycle holding the empty slot costs its length minus one, any other costs its length plus one.

Open the interactive visualisation