Kids With the Greatest Number of Candies

There are n kids, and kid i has candies[i] candies. You also hold extraCandies candies. For each kid, decide whether giving that kid all of the extra candies would leave them with at least as many candies as every other kid (several kids may tie for the most). Return a boolean array result where result[i] is true if kid i would have the greatest number of candies, and false otherwise.

30:00

Kids With the Greatest Number of Candies
easy
Free written solution
Topics
Companies

There are n kids, and kid i has candies[i] candies. You also hold extraCandies candies. For each kid, decide whether giving that kid all of the extra candies would leave them with at least as many candies as every other kid (several kids may tie for the most). Return a boolean array result where result[i] is true if kid i would have the greatest number of candies, and false otherwise.

Example 1:
Input: {"candies":[2,3,5,1,3],"extraCandies":3}
Output: [true,true,true,false,true]
Constraints:
  • n==candies.lengthn == \text{candies.length}

  • 2≤n≤1002 \leq n \leq 100

  • 1≤candies[i]≤1001 \leq \text{candies}[i] \leq 100

  • 1≤extraCandies≤501 \leq \text{extraCandies} \leq 50

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"candies":[2,3,5,1,3],"extraCandies":3}

candies[i]

extraCandies = 3

most = 2

2031521334most = 2

result

?
?
?
?
?

Kid 0 has 2, the first record to beat.

Variables
VariableValue
i0
most2
DepthFunction Call
Stack empty
0/17