BackhardSorting

Custom Digit Sorting Solution

Problem Statement

Given an array of non-negative integers and two integers, customBase and k, implement a custom radix sort to sort the array. The custom radix sort should use the customBase and should not consider more than k digits for sorting. If a number cannot be represented in the customBase within k digits, it should be placed at the end of the sorted array in their original order.

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

Explanation: The array is sorted using a custom radix sort with customBase = 10 and k = 3

Example 2
Input
[1000, 23, 56, 789, 24, 1, 7, 9]
Output
[1, 7, 9, 23, 24, 56, 789, 1000]

Explanation: The array is sorted using a custom radix sort with customBase = 10 and k = 4

Constraints

  • 1 <= customBase <= 16
  • 1 <= k <= 10
  • 1 <= array length <= 1000
  • 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