Given an array, determine the fewest swaps needed to arrange it in sorted order. Each operation may exchange the values at any two indices. The interview variants include:
Descending variant:
[3, 4, 1, 2] -> [4, 3, 1, 2] -> [4, 3, 2, 1]
nums = [3,4, 1, 2] order = desc
2
Given array [3, 4, 1, 2] and we need to sort it in descending order.
The minimum is 2 swaps.
nums = [3,4, 1, 2] order = desc
2
Given array [3, 4, 1, 2] and we need to sort it in descending order.