EasyNo. 1431

Kids With the Greatest Number of Candies — LeetCode 1431 Python Solution

Topics
Array
On a study list
LeetCode 75
Reading time
2 min

The problem

There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the ith kid has, and an integer extraCandies, denoting the number of extra candies that you have.

Example

Input
candies = [2,3,5,1,3], extraCandies = 3
Output
[true,true,true,false,true]
Explanation
If you give all extraCandies to:

Python solution

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

Complexity

Time
O(n)
Space · auxiliary
O(1) to O(n)

Related problems

Frequently asked questions

How hard is LeetCode 1431. Kids With the Greatest Number of Candies?

LeetCode 1431. Kids With the Greatest Number of Candies is rated Easy on LeetCode.

What topics does LeetCode 1431. Kids With the Greatest Number of Candies cover?

LeetCode 1431. Kids With the Greatest Number of Candies is tagged Array on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity, invisible to screen sharing.

Free to download. Check it runs on your machine, then pick a plan.