Show problems as
Classic problem #1431EasyArray

Kids With the Greatest Number of Candies

Real-world version: Bonus Sheet Leaders
Tracked in this browser only
Read Kids With the Greatest Number of Candies on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A collectors' club keeps a register of how many stamps each member owns, with stamps[i] the count held by member i. One bonus sheet carrying bonus further stamps is up for grabs.

Ask the same question of every member in turn: if this member alone were handed the whole bonus sheet, would their new count be at least as large as the count every other member holds today? Ties count as yes, and more than one member can answer yes.

Return a list answer of the same length as stamps, where answer[i] is true when member i answers yes and false when they do not. Every question is judged against the register as it stands, since the sheet is only ever handed out hypothetically.

Examples

Example 1

Input
stamps = [6,9,4,9], bonus = 2
Output
[false,true,false,true]

The largest holding on the register is 9. Member 0 would reach 8 and member 2 would reach 6, both short of 9. Members 1 and 3 would each reach 11.

Example 2

Input
stamps = [7,7], bonus = 1
Output
[true,true]

Either member would reach 8, which clears the other member's 7.

Example 3

Input
stamps = [3,20,5], bonus = 17
Output
[true,true,true]

Member 0 would reach exactly 20, which ties the largest holding and so counts as yes. Member 1 would reach 37 and member 2 would reach 22.

Example 4

Input
stamps = [50,10,30], bonus = 19
Output
[true,false,false]

The largest holding is 50. Member 1 would reach 29 and member 2 would reach 49, both short of it, while member 0 would reach 69.

Example 5

Input
stamps = [8,5], bonus = 3
Output
[true,true]

Member 1 would reach exactly 8, level with member 0's holding, and a tie answers yes.

Constraints

  • n == stamps.length
  • 2 <= n <= 100
  • 1 <= stamps[i] <= 100
  • 1 <= bonus <= 50

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def kids_with_candies(stamps: list[int], bonus: int) -> list[bool]:
Java
public List<Boolean> kidsWithCandies(int[] stamps, int bonus)