Skip to content

Commit af836f0

Browse files
committed
Add problem 3190: Find Minimum Operations to Make All Elements Divisible by Three
1 parent ba77cf1 commit af836f0

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,6 +2127,7 @@ pub mod problem_3179_find_the_n_th_value_after_k_seconds;
21272127
pub mod problem_3184_count_pairs_that_form_a_complete_day_i;
21282128
pub mod problem_3185_count_pairs_that_form_a_complete_day_ii;
21292129
pub mod problem_3186_maximum_total_damage_with_spell_casting;
2130+
pub mod problem_3190_find_minimum_operations_to_make_all_elements_divisible_by_three;
21302131
pub mod problem_3350_adjacent_increasing_subarrays_detection_ii;
21312132

21322133
#[cfg(test)]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
pub struct Solution;
2+
3+
// ------------------------------------------------------ snip ------------------------------------------------------ //
4+
5+
impl Solution {
6+
pub fn minimum_operations(nums: Vec<i32>) -> i32 {
7+
nums.iter().map(|&num| i32::from(num.cast_unsigned() % 3 != 0)).sum()
8+
}
9+
}
10+
11+
// ------------------------------------------------------ snip ------------------------------------------------------ //
12+
13+
impl super::Solution for Solution {
14+
fn minimum_operations(nums: Vec<i32>) -> i32 {
15+
Self::minimum_operations(nums)
16+
}
17+
}
18+
19+
#[cfg(test)]
20+
mod tests {
21+
#[test]
22+
fn test_solution() {
23+
super::super::tests::run::<super::Solution>();
24+
}
25+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pub mod iterative;
2+
3+
pub trait Solution {
4+
fn minimum_operations(nums: Vec<i32>) -> i32;
5+
}
6+
7+
#[cfg(test)]
8+
mod tests {
9+
use super::Solution;
10+
11+
pub fn run<S: Solution>() {
12+
let test_cases = [(&[1, 2, 3, 4] as &[_], 3), (&[3, 6, 9], 0)];
13+
14+
for (nums, expected) in test_cases {
15+
assert_eq!(S::minimum_operations(nums.to_vec()), expected);
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)