02 · Arrays & Strings in Java

#1431 Kids With the Greatest Number of Candies

Easysolve on LeetCode ↗

frequently reported atAmazonMetaMicrosoft

the problem

In plain words

candies[i] is how many candies kid i has. For each kid, imagine giving them all extraCandies. Would they then have at least as many as every other kid? Return one true/false per kid as a List<Boolean>.

in candies = [2,3,5,1,3], extraCandies = 3

out [true,true,true,false,true]

Only kid 3 (1 + 3 = 4) stays below the current max of 5.

in candies = [4,2,1,1,2], extraCandies = 1

out [true,false,false,false,false]

in candies = [12,1,12], extraCandies = 10

out [true,false,true]

  • 2 ≤ n ≤ 100
  • 1 ≤ candies[i] ≤ 100
  • 1 ≤ extraCandies ≤ 50

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #1672
      Richest Customer Wealth
      Easyin Java Arrays & Strings
    2. #121
      Best Time to Buy and Sell Stock
      Easyin Arrays & Strings