File: kids-with-the-greatest-number-of-candies/solution.py

Date: 2026-06-06

Time: 17:11

kids-with-the-greatest-number-of-candies/solution.py

Purpose

Solves LeetCode 1431 — Kids With the Greatest Number of Candies. Given a list of candy counts per kid and a number of extra candies, determine which kids would have the maximum (or tied-for-maximum) count if they alone received all the extra candies.

Key Components

Solution.kidsWithCandies(candies, extraCandies) -> List[bool] — the single method. Contract:

Patterns

Dependencies

Flow

1. max(candies) scans the full list to find the current global maximum.

2. The list comprehension iterates each kid's count c, checks if c + extraCandies meets or exceeds that maximum, and collects the booleans.

3. Returns the result directly — no mutation of input.

Invariants

Error Handling

None. The function trusts its caller to provide valid input per the problem constraints. An empty candies list would propagate a ValueError from max().

Topics to Explore

Beliefs