Distribute Money to Maximum Children
Real-world version: Badges at the Token CounterThe statement here is our own: the same inputs, outputs and technique.
An arcade attendant has tokens tokens to hand out across players players waiting at the counter. The house rules are:
- every token must be handed out;
- every player must leave with at least one token;
- no player may leave with exactly four tokens, a count the arcade considers unlucky.
A player who leaves with exactly eight tokens is also given a free badge.
Return the largest number of badges the attendant can award. If no handout satisfies all three rules, return -1.
Examples
Example 1
- Input
- tokens = 24, players = 3
- Output
- 3
Handing eight tokens to each player uses all 24, gives everyone at least one and leaves nobody on exactly four, so all three players collect a badge.
Example 2
- Input
- tokens = 10, players = 2
- Output
- 1
Handing out eight and two tokens uses all ten, gives both players at least one and leaves neither on exactly four. One player holds eight, so one badge is awarded.
Example 3
- Input
- tokens = 12, players = 2
- Output
- 0
Handing out five and seven tokens uses all twelve, gives both players at least one and leaves neither on exactly four. Neither player holds eight, so no badge is awarded.
Example 4
- Input
- tokens = 1, players = 2
- Output
- -1
One token cannot give two players at least one each, so no handout satisfies the rules.
Constraints
- 1 <= tokens <= 200
- 2 <= players <= 30
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def most_badges(tokens: int, players: int) -> int:public int mostBadges(int tokens, int players)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 22 test cases: 22 passed
- Passed: 4 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Minimum Cost to Move Chips to The Same PositionReal-world version: Shunting Pallets Into One BayEasy
- Minimum Number of Pushes to Type Word IReal-world version: Eight-Key Field TerminalEasy
- Largest Odd Number in StringReal-world version: Largest Odd Segment of a SerialEasy
- K Items With the Maximum SumReal-world version: Best Handful From the Token TinEasy