Sort an array of integers in ascending order based on the digital root, which is the value obtained by recursive sum of its digits until only a single digit remains
Explanation: The digital root of 12 is 3 (1+2=3), of 13 is 4 (1+3=4), of 25 is 7 (2+5=7), of 67 is 13 (6+7=13, 1+3=4), and of 89 is 17 (8+9=17, 1+7=8). So, the array is sorted in ascending order based on the digital roots.
Explanation: The digital root of 9 is 9, of 100 is 1 (1+0+0=1), of 200 is 2 (2+0+0=2), and of 38 is 2 (3+8=11, 1+1=2). So, the array is sorted in ascending order based on the digital roots.
Non-comparison based sorting
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak