Trains the technique from
LeetCode 1464Maximum Product of Two Elements 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 shop prints a run of vouchers. Voucher i shows the face value tokens[i], and handing it in converts to tokens[i] - 1 credits. Two vouchers may carry the same face value.
Choose two vouchers at different positions i and j. The payout for that choice is the product of their credit amounts. Return the largest payout any such choice gives.
Example 1
Taking the vouchers showing 10 and 9 gives credits of 9 and 8, and their product is 72.
Example 2
The two vouchers showing 6 sit at different positions, so both may be used. Each converts to 5 credits, and 5 times 5 is 25.
Example 3
Only one pair exists. The voucher showing 1 converts to 0 credits, so the payout is 0 times 999, which is 0.
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 max_product(tokens: list[int]) -> int:public int maxProduct(int[] tokens)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.