You are given an array nums of distinct positive integers. You need to sort the array in increasing order based on the sum of the digits of each number. If two numbers have the same digit sum, the smaller number appears first in the sorted order. Return the minimum number of swaps required to rearrange nums into this sorted order. A swap is defined as exchanging the values at two distinct positions in the array.
Example 1
Input: nums = [37,100]
Output: 1
Explanation: Digit sums are 10 and 1, so the sorted order is [100, 37]. One swap exchanges 37 and 100 to reach it.
Example 2
Input: nums = [22,14,33,7]
Output: 0
Explanation: Digit sums are 4, 5, 6, 7, already increasing, so the array is sorted and no swaps are needed.
Example 3
Input: nums = [18,43,34,16]
Output: 2
Explanation: Sorted order is [16, 34, 43, 18]; swapping 18 with 16 and 43 with 34 gets there in two swaps.
Figure out where every value must end up, then count cycles in that rearrangement — each cycle of length k needs exactly k-1 swaps.
Run checks all cases above. Submit evaluates all test cases.