A design tool exports a palette as hex color codes like "#a1b2c3": a # followed by exactly six characters, each a digit 0-9 or a lowercase letter a-f. The export must list the codes in dictionary order, comparing character codes from left to right.
Write sortPalette(codes) that returns a new array with the codes in that order, keeping duplicates. Because every code has the same length, you can sort them with least-significant-character radix sort: one stable pass per character position, from the last character to the first.
Input: codes = ["#ff0000","#00ff00","#0000ff"] Output: ["#0000ff","#00ff00","#ff0000"]
Digits come before letters, and 0 comes before f.
Input: codes = ["#abcdef","#abcdee"] Output: ["#abcdee","#abcdef"]
They differ only in the last character.
0 <= codes.length <= 100000# plus six characters from 0-9a-f.Run 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 #206 Sort a Palette of Hex Colors. 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.