Sorted Numbers
Solve a medium-level problem of sorting numbers in range in lexicographical order using tries.
Problem statement
Given an integer
Example 1
Sample input
n = 13
Sample output
[1,10,11,12,13,2,3,4,5,6,7,8,9]
Explanation
Sorting the values lexicographically [1,2,3,4,5,6,7,8,9,10,11,12,13] results in [1,10,11,12,13,2,3,4,5,6,7,8,9]
Example 2
Sample input
n = 3
Sample output
[1,2,3]
Explanation
Sorting the values [1,2,3] lexicographically, results in [1,2,3]
Try it yourself
Try to solve the problem yourself before reading the solution.
Intuition
The first idea that strikes the mind is to iterate through all the integers from
Analyzing this problem closely, we can observe that all the numbers starting with