A sorting tutorial shows radix sort one digit at a time. Each pass looks at one decimal digit, starting with the ones digit: it goes through the numbers in their current order and puts each into one of ten buckets by that digit, then joins the buckets from 0 to 9. The next pass uses the tens digit, and so on. There is one pass for each digit of the largest number.
Write radixPasses(nums) that returns an array of snapshots: the list after each pass. If the largest number is 0 (or the list is empty), there are no passes, so return [].
Input: nums = [170,45,75,90,2,802,24,66] Output: [[170,90,2,802,24,45,75,66],[2,802,24,45,66,170,75,90],[2,24,45,66,75,90,170,802]]
Three passes, for the ones, tens, and hundreds digits of 802.
Input: nums = [3,1,2] Output: [[1,2,3]]
Every number has one digit, so one pass sorts them.
0 <= nums.length <= 10^50 <= nums[i] <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #205 Radix Sort Digit by Digit. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.