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
- 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
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
| No. | Problem | Difficulty |
|---|---|---|
| 1437 | Check If All 1's Are at Least Length K Places Away | Easy |
| 0057 | Insert Interval | Medium |
| 0228 | Summary Ranges | Easy |
| 0485 | Max Consecutive Ones | Easy |
| 0665 | Non-decreasing Array | Medium |
| 0674 | Longest Continuous Increasing Subsequence | Easy |
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.