← 返回 jpmorgan 的题目列表Minimum Number of Swaps to Sort an Array Decreasingly
类型:online_judge
Given an array of numbers, your task is to sort it in descending order using the minimum number of swaps. Return the minimum number of swaps required for the sort.
Input Description:
A list of n unique integers, where 1 <= n <= 1000.
Output Description:
An integer representing the minimum number of swaps needed to sort the array.
Example:
Input: [4, 3, 1, 2] Output: 3
Input: [1, 5, 4, 3, 2] Output: 2
Example
Input
4 3 1 2