human
I found an interesting problem on https://leetcode.com/problems/k-th-smallest-in-lexicographical-order/:
Given integers n and k, find the lexicographically k-th smallest integer in the range from 1 to n.

Note: 1 ≤ k ≤ n ≤ 109.

Example:

Input:
n: 13   k: 2

Output:
10

Explanation:
The lexicographical order is [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9], so the second smallest number is 10.

I tried it in Python, but could not do it. Can you solve it?

Can you provide a Python program to find the lexicographically k-th smallest integer in the range from 1 to n?
assistant
#Here is Python program to find the lexicographically k-th smallest integer in the range from 1 to n.

class Solution:
     def findKthNumber(self, n, k):
         self.d = {}
         res = 1
         k -= 1
         while k> 0:
             #calculate how many numbers between current value and current value + 1
             count = self.countNumber(res,res + 1,n)
             if k >= count:
                 #result >= res +1
                 k -= count
                 res += 1
             else:
                 #res*10 <= result < res + 1
                 k -= 1
                 res *= 10
         return res
     
     def countNumber(self,l,r,maxValue):
         if l > maxValue:
             return 0
         if (l,r) in self.d:
             return d[(l,r)]
         res = min(maxValue + 1,r) - l 
         l *= 10
         r *= 10
         res += self.countNumber(l,r,maxValue)
         self.d[(l,r)] = res
         return res