Order by Digit Sum — Solution & Editorial
Sort with the composite key: (digit_sum(x), x). Stability/tie-breaks come from including the value itself in the key.
Complexity: O(N log N · key cost)
Sort with the composite key: (digit_sum(x), x). Stability/tie-breaks come from including the value itself in the key.
Complexity: O(N log N · key cost)