Trains the technique from
LeetCode 1539Kth Missing Positive NumberThis 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 depot labels its parking bays 1, 2, 3 and onward, and the labelling never stops, so there is no highest bay. taken lists the bays already let out to tenants in strictly increasing order, which means no bay is listed twice. Any bay whose label does not appear in taken is free.
Given taken and an integer k, return the label of the k-th smallest free bay.
Free bays carry on past the largest label in taken, so the answer may well be larger than every entry in the list. Since taken arrives in order, aim for a running time of O(log n) in its length rather than reading every entry.
Example 1
The free labels in order are 1, 2, 5, 6, 7, 10, and so on. The fourth of them is 6.
Example 2
Bays 1, 2 and 3 are let out, so the free labels start 4, 5, 6, 7, 8 and the fifth is 8.
Example 3
Only bay 6 is let out, so the free labels run 1, 2, 3, 4, 5, 7, and the sixth is 7.
Example 4
Nothing below 9 is let out, so the free labels begin 1, 2, 3, 4 and the fourth is 4.
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 kth_free_bay(taken: list[int], k: int) -> int:public int kthFreeBay(int[] taken, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.