BackhardSorting

Digit Distribution Sorting Solution

Problem Statement

Given an array of non-negative integers, sort the array in ascending order using a non-comparison sorting technique. The array may contain duplicate values.

Example 1
Input
[170, 45, 75, 90, 802, 24, 2, 66]
Output
[2, 24, 45, 66, 75, 90, 170, 802]

Explanation: The input array is sorted using radix sort, where each digit position is processed individually to achieve the sorted output.

Example 2
Input
[100, 25, 11, 9, 3, 2, 1, 0]
Output
[0, 1, 2, 3, 9, 11, 25, 100]

Explanation: Radix sort iterates through each digit position, counting the occurrences of each digit and rearranging the array accordingly, resulting in the sorted output.

Constraints

  • 1 <= 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