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

EasyArray
Problem
#1431
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

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

Complexity

MeasureComplexity
TimeO(n)
SpaceO(1) to O(n) auxiliary

Related problems

On a study list

This problem is on LeetCode 75.

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.

Get Stealth Interview