K-th Smallest in Lexicographical Order

Hard

Company Tags

You are given two integers n and k, return the kth lexicographically smallest integer in the range [1, n].

Example 1:

Input: n = 10, k = 3

Output: 2

Explanation: The lexicographical order is [1,10,2,3,4,5,6,7,8,9]. The third smallest number is 2.

Example 2:

Input: n = 11, k = 3

Output: 2

Explanation: The lexicographical order is [1,10,11,2,3,4,5,6,7,8,9]. The third smallest number is 11.

Constraints:

  • 1 <= k <= n <= 1,000,000,000


Company Tags

Please upgrade to NeetCode Pro to view company tags.

n =

k =