LeetCode Entry

1431. Kids With the Greatest Number of Candies

17.04.2023 easy 2023 kotlin

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()

blog post substack

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)\)