Problem
Ask
Submissions

Problem: K-th Smallest in Lexicographical Order

Medium
30 min
Understand how to identify the k-th smallest number in lexicographical order from a range of integers. Explore methods that order numbers digit by digit like dictionary words, using trie structures to optimize the search process. Develop skills to apply these patterns in coding interviews and implement solutions efficiently.

Statement

Given two integers, n and k, return the kthk^{th} smallest number in the range [1, n] when the numbers are sorted lexicographically.

Note: Lexicographical sorting means ordering numbers like words in a dictionary (alphabetical order)—digit by digit from left to right. For example, the numerical order of 1, 5, and 10 is [1, 5, 10], but their lexicographical order is [1, 10, 5].

Constraints:

  • 11 \leq k \leq n 109\leq 10^9

Problem
Ask
Submissions

Problem: K-th Smallest in Lexicographical Order

Medium
30 min
Understand how to identify the k-th smallest number in lexicographical order from a range of integers. Explore methods that order numbers digit by digit like dictionary words, using trie structures to optimize the search process. Develop skills to apply these patterns in coding interviews and implement solutions efficiently.

Statement

Given two integers, n and k, return the kthk^{th} smallest number in the range [1, n] when the numbers are sorted lexicographically.

Note: Lexicographical sorting means ordering numbers like words in a dictionary (alphabetical order)—digit by digit from left to right. For example, the numerical order of 1, 5, and 10 is [1, 5, 10], but their lexicographical order is [1, 10, 5].

Constraints:

  • 11 \leq k \leq n 109\leq 10^9