Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
There are two possibilities for nums to be sorted. Find the minimum number of operations needed for the first possibility, then find the minimum number of operations needed for the second possibility. The answer is the minimum out of the two.
If the empty space is not at its ending position, then you can move the item that should be where the empty space is to the empty space.
If the empty space is at its ending position, then you need to move an out-of-place item to the empty space.