Minimum swaps to sort array

Write codeMedium30 min

Your task

Given an array a of distinct integers, return the minimum number of swaps (each swap exchanges any two positions) needed to sort the array in ascending order. The array length can be 1.

Examples

min_swaps_to_sort(a: list[int]) -> int
Example 1
Inputmin_swaps_to_sort([2, 1, 3, 4])
Output1