We’re preparing your current view and syncing the latest data.
Given two integers n and k, return the k-th smallest integer in the range [1, n] when the integers are ordered lexicographically (as strings). For example, given n = 13, the numbers arranged lex order are: 1,10,11,12,13,2,3,... and so on. You need to return the k-th number in this order.
Two integers n and k where 1 <= k <= n <= 10^9.
Return an integer representing the k-th smallest number in lexicographical order within the range [1, n].
1 <= k <= n <= 10^9
Example 1
Input
n = 13, k = 2
Output
10
Explanation
The lexicographical order up to 13 is [1,10,11,12,13,2,3,4,5,6,7,8,9]. The 2nd number is 10.
Example 2
Input
n = 100, k = 90
Output
9
Explanation
The 90th number in lex order up to 100 is 9.