class Solution {
public:
vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies) {
int max_candies = *max_element(candies.begin(), candies.end());
for (int i = 0; i < candies.size(); i++) {
candies[i] = candies[i] + extraCandies >= max_candies;
}
vector<bool> result(candies.size());
transform(candies.begin(), candies.end(), result.begin(), [](int i) { return i == 1; });
return result;
}
};
leetcode
challenge
Here is the link for the problem:
https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/
Top comments (0)