BackmediumSorting

Least Significant Digit Frequency Sort Solution

Problem Statement

Given an array of non-negative integers, sort the array based on the frequency of the least significant digit of each number in the entire array. If two numbers have the same frequency of the least significant digit, sort them based on the value of the least significant digit itself.

Example 1
Input
[127, 256, 354, 413, 624]
Output
[413,256,127,354,624]

Explanation: The frequency of the least significant digit in the entire array is counted and sorted accordingly.

Example 2
Input
[100, 100, 200, 201]
Output
[201,100,100,200]

Explanation: The frequency of the least significant digit in the entire array is counted and sorted accordingly.

Constraints

  • 0 <= array length <= 10^5
  • 0 <= array elements <= 10^6
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free