2489. Sort Array by Moving Items to Empty Space

Hard
Array
Greedy
Sorting

Description

Hints

Hint 1
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.
Hint 2
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.
Hint 3
If the empty space is at its ending position, then you need to move an out-of-place item to the empty space.

Statistics

Acceptance
45.2%
Submissions
6,251
Accepted
2,825