From d8009b9a4a482fab26e3b47221b69a9b38cb5e11 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Mon, 17 Apr 2023 18:51:10 +0200 Subject: [PATCH] =?UTF-8?q?problems(rs):=20add=20=E2=80=9C1431.=20Kids=20W?= =?UTF-8?q?ith=20the=20Greatest=20Number=20of=20Candies=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- ...ids-with-the-greatest-number-of-candies.rs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 problems/kids-with-the-greatest-number-of-candies.rs diff --git a/problems/kids-with-the-greatest-number-of-candies.rs b/problems/kids-with-the-greatest-number-of-candies.rs new file mode 100644 index 0000000..07c48f7 --- /dev/null +++ b/problems/kids-with-the-greatest-number-of-candies.rs @@ -0,0 +1,41 @@ +struct Solution {} +impl Solution { + pub fn kids_with_candies(candies: Vec, extra_candies: i32) -> Vec { + let max = *candies.iter().max().unwrap(); + candies + .iter() + .map(|candies| candies + extra_candies >= max) + .collect() + } +} + +fn main() {} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn example_1() { + assert_eq!( + Solution::kids_with_candies(vec![2, 3, 5, 1, 3], 3), + vec![true, true, true, false, true] + ); + } + + #[test] + fn example_2() { + assert_eq!( + Solution::kids_with_candies(vec![4, 2, 1, 1, 2], 1), + vec![true, false, false, false, false] + ); + } + + #[test] + fn example_3() { + assert_eq!( + Solution::kids_with_candies(vec![12, 1, 12], 10), + vec![true, false, true] + ); + } +}