Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Ones created using a change require <code>2</code> moves. Hence except for the immediate neighbors of the index where we move all the ones, we should try to use change operations.
For some subset of ones, it is always better to move the ones to the median position.
We only need to be concerned with the indices where <code>nums[i] == 1</code>.