2474. Minimum Adjacent Swaps to Make a Valid Array

Medium
Array
Greedy

Description

Hints

Hint 1
Notice that in order to obtain the minimum swaps, we should focus on the smallest element that is the leftmost and the largest element that is the rightmost.
Hint 2
We can take those elements and greedily only do swaps that bring them closer to their respective end positions.

Statistics

Acceptance
72.2%
Submissions
55,945
Accepted
40,401