Search
⌘K

Leetcode 3086. Minimum Moves to Pick K Ones

Choose any start index and, using at most maxChanges zero→one flips (each counting as a move) and adjacent swaps of 1s toward your position (each swap counts as a move; picking a 1 at your index is free), collect exactly k ones with minimum moves. Algorithmically this is about selecting k target positions (possibly turning some zeros into ones) and minimizing the total adjacent-swap distance to aggregate them at some center under a flip budget, typically handled by working on the positions-of-ones with sliding-window/prefix-cost techniques.


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.