FunctionRacerProblemsRace

Kth Number in Dictionary Order

HardMathPython, JavaScript, TypeScript, Java, C++

Write the whole numbers from 1 to n as text and sort them the way a dictionary sorts words, so 10 comes before 9 and 101 comes before 11.

Return the number at place k of that order, counting from 1.

Example 1

n 25
k 5
returns 13

The order starts 1, 10, 11, 12, 13. The fifth number is 13.

Example 2

n 100
k 4
returns 11

The order starts 1, 10, 100, 11. The fourth number is 11.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems