Tap here to switch tabs
Problem
Submissions

Problem: Minimum Swaps to Sort by Digit Sum

Try to solve the Minimum Swaps to Sort by Digit Sum problem.

Statement

You are given an array nums of distinct positive integers.

You want to sort nums such that each element is ordered primarily in ascending order of its digit sum. If two elements have the identical digit sum, they should be ordered in ascending order of their values.

Return the minimum number of swaps required to sort nums into this order.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • nums consists of distinct positive integers.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Swaps to Sort by Digit Sum

Try to solve the Minimum Swaps to Sort by Digit Sum problem.

Statement

You are given an array nums of distinct positive integers.

You want to sort nums such that each element is ordered primarily in ascending order of its digit sum. If two elements have the identical digit sum, they should be ordered in ascending order of their values.

Return the minimum number of swaps required to sort nums into this order.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • nums consists of distinct positive integers.