Trains the technique from
LeetCode 1394Find Lucky Integer in an 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 tray holds tokens whose face values are listed in tokens. A value is matched when the tray holds exactly that many tokens of it, so 3 is matched when exactly three tokens show 3.
Return the largest matched value, or -1 when the tray holds no matched value at all.
Example 1
Three tokens show 2, which is one too many for 2 to be matched, and no other value appears at all.
Example 2
Four tokens show 4 and five show 5, so both values are matched and the larger is reported.
Example 3
A lone token showing 1 is matched, since 1 turns up exactly once.
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_lucky(tokens: list[int]) -> int:public int findLucky(int[] tokens)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.