Given an array of non-negative integers, sort the array based on the frequency of the least significant digit of each number in ascending order, and then by the least significant digit itself in ascending order. If two or more numbers have the same least significant digit and frequency, their original order is preserved.
Explanation: The frequency of the least significant digit for each number is as follows: 3 (1 time), 2 (2 times), 7 (1 time), 4 (1 time), 2 (2 times). Sorting based on this frequency and then by the digit gives the output.
Explanation: The frequency of the least significant digit for each number is the same (1 time), so the output is sorted by the least significant digit itself in ascending order.
Non-comparison based sorting
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak