LeetCode Entry
1431. Kids With the Greatest Number of Candies
Let's write the code
1431. Kids With the Greatest Number of Candies easy
fun kidsWithCandies(candies: IntArray, extraCandies: Int): List<Boolean> =
candies.max()?.let { max ->
candies.map { it + extraCandies >= max}
} ?: listOf()
Join me on Telegram
https://t.me/leetcode_daily_unstoppable/183
Intuition
We can just find the maximum and then try to add extra to every kid and check
Approach
Let’s write the code
Complexity
- Time complexity: \(O(n)\)
- Space complexity: \(O(1)\)