Trains the technique from
LeetCode 440K-th Smallest in Lexicographical OrderThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A bonded warehouse labels its lots with the whole numbers from 1 up to n. The printed manifest treats each label as a piece of text and puts the labels in dictionary order, comparing one character at a time. Under that ordering the label 10 is printed before the label 2, and 100 is printed before 11.
Given n and a position k, return the label that occupies position k of the manifest. Positions are numbered from 1, so position 1 always holds the label 1.
The warehouse may hold as many as a billion lots, so building the whole manifest is out of the question; the answer must be found without listing the labels one at a time.
Example 1
Position 208 of the manifest for 725 lots holds the label 286. Exactly 207 of the labels from 1 to 725 come before 286 in dictionary order.
Example 2
With 46 lots the manifest has 46 entries, and its final entry is the label 9, because every other label starts with a smaller character.
Example 3
Exactly four labels precede the label 2 in dictionary order, namely 1 followed by the three labels 10, 11 and 12 that begin with the character 1. That puts the label 2 at position 5.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def find_kth_number(n: int, k: int) -> int:public int findKthNumber(int n, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.