BackeasySorting

Digit Frequency Sorting Solution

Problem Statement

Given an array of non-negative integers, sort the array based on the number of digits in each number. If two numbers have the same number of digits, their original order is preserved.

Example 1
Input
[123, 45, 67, 12, 89]
Output
[123,45,67,12,89]
Example 2
Input
[1000, 9, 99, 999]
Output
[1000,9,99,999]

Constraints

  • 0 <= each number in the array <= 10000
  • Each number in the array is non-negative
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