All problems
0703EasyMathGreedy

Badges at the Token Counter

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2591Distribute Money to Maximum Children

This 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.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def most_badges(tokens: int, players: int) -> int:
Java
public int mostBadges(int tokens, int players)
September 7
Apply