SDE & MLE Prep

1431. Kids With the Greatest Number of Candies

Problem

candies[i] is how many candies kid i has. For each kid, report whether giving them all extraCandies would leave them with at least as many candies as every other kid.

Example: candies = [2,3,5,1,3], extraCandies = 3 → [true,true,true,false,true]

A kid can become the (tied) maximum iff candies[i] + extra >= max(candies).

Complexity: O(n).

class Solution:
    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:
        best = max(candies)
        return [c + extraCandies >= best for c in candies]