Talentd
FleetCode

440. K-th Smallest in Lexicographical Order

Hard46.2% acceptance7 companies

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

Example 1:

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.

Example 2:

Input: n = 1, k = 1
Output: 1

Constraints:

  • 1 <= k <= n <= 109

Topics

19:06
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def findKthNumber(self, n: int, k: int) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
13
2
Input
1
1
Your code is saved on this device.Solution