1431. Kids With the Greatest Number of Candies Easy

@problem@discussion
#Array



1/**
2 * [1431] Kids With the Greatest Number of Candies
3 *
4 * There are n kids with candies. You are given an integer array candies, where each candies[i] represents the number of candies the i^th kid has, and an integer extraCandies, denoting the number of extra candies that you have.
5 * Return a boolean array result of length n, where result[i] is true if, after giving the i^th kid all the extraCandies, they will have the greatest number of candies among all the kids, or false otherwise.
6 * Note that multiple kids can have the greatest number of candies.
7 *  
8 * Example 1:
9 * 
10 * Input: candies = [2,3,5,1,3], extraCandies = 3
11 * Output: [true,true,true,false,true] 
12 * Explanation: If you give all extraCandies to:
13 * - Kid 1, they will have 2 + 3 = 5 candies, which is the greatest among the kids.
14 * - Kid 2, they will have 3 + 3 = 6 candies, which is the greatest among the kids.
15 * - Kid 3, they will have 5 + 3 = 8 candies, which is the greatest among the kids.
16 * - Kid 4, they will have 1 + 3 = 4 candies, which is not the greatest among the kids.
17 * - Kid 5, they will have 3 + 3 = 6 candies, which is the greatest among the kids.
18 * 
19 * Example 2:
20 * 
21 * Input: candies = [4,2,1,1,2], extraCandies = 1
22 * Output: [true,false,false,false,false] 
23 * Explanation: There is only 1 extra candy.
24 * Kid 1 will always have the greatest number of candies, even if a different kid is given the extra candy.
25 * 
26 * Example 3:
27 * 
28 * Input: candies = [12,1,12], extraCandies = 10
29 * Output: [true,false,true]
30 * 
31 *  
32 * Constraints:
33 * 
34 * 	n == candies.length
35 * 	2 <= n <= 100
36 * 	1 <= candies[i] <= 100
37 * 	1 <= extraCandies <= 50
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/
43// discuss: https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn kids_with_candies(candies: Vec<i32>, extra_candies: i32) -> Vec<bool> {
49        vec![]
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_1431() {
61    }
62}
63


Back
© 2025 bowen.ge All Rights Reserved.