Trains the technique from
LeetCode 33Search in Rotated Sorted ArrayThis 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 catalogue drawer holds cards stamped with reference numbers, no two alike. Numbering starts below zero for retired stock, so a reference number may be negative.
The cards were filed strictly increasing from front to back. Afterwards a clerk cut the drawer at one point, lifted out the block in front of the cut and set it down behind the remaining block, leaving both blocks in their own order. If the clerk happened to cut right at the very front, nothing actually moved and the drawer is still plainly increasing.
cards is the drawer as it reads today, front to back. Given a reference number wanted, return the index of the card carrying it, or -1 when the drawer holds no such card. Reference numbers never repeat, so at most one index can be the answer.
Pulling a card out to read it is the expensive step, so the number of cards you inspect has to grow only with the logarithm of the drawer size. Working front to back through the drawer is too many reads.
Example 1
Filed in order the drawer would read -5, 1, 4, 7, 9, 12; the clerk cut before 7 and moved the block -5, 1, 4 to the back. Card 1 now sits at index 4.
Example 2
The cut fell at the very front, so nothing moved and the drawer still increases throughout. Card 8 is last, at index 2.
Example 3
The number 6 would slot between 4 and 7 in the filed order, but no card carries it, so the drawer reports nothing.
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 locate_card(cards: list[int], wanted: int) -> int:public int locateCard(int[] cards, int wanted)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.