Kids With the Greatest Number of Candies — LeetCode 1431 Python Solution
EasyArray
- Problem
- #1431
- Reading time
- 2 min
- Source
- leetcode.com
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
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(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.