aboutsummaryrefslogtreecommitdiff
path: root/other/min_rounds_complete_all_tasks.rs
diff options
context:
space:
mode:
Diffstat (limited to 'other/min_rounds_complete_all_tasks.rs')
-rw-r--r--other/min_rounds_complete_all_tasks.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/other/min_rounds_complete_all_tasks.rs b/other/min_rounds_complete_all_tasks.rs
new file mode 100644
index 0000000..1c9b7dd
--- /dev/null
+++ b/other/min_rounds_complete_all_tasks.rs
@@ -0,0 +1,30 @@
+use std::collections::HashMap;
+struct Solution;
+
+impl Solution {
+ pub fn minimum_rounds(tasks: Vec<i32>) -> i32 {
+ let (mut map, mut ans) = (HashMap::new(), 0);
+ for t in tasks {
+ let val = map.get_mut(&t);
+ if let Some(v) = val {
+ *v += 1;
+ } else {
+ map.insert(t, 1);
+ }
+ }
+ for c in map.into_values() {
+ if c == 1 {
+ return -1;
+ }
+ ans += (c + 2) / 3;
+ }
+ ans
+ }
+}
+
+fn main() {
+ let tasks1 = vec![2,2,3,3,2,4,4,4,4,4];
+ let tasks2 = vec![2,3,3];
+ println!("{}", Solution::minimum_rounds(tasks1));
+ println!("{}", Solution::minimum_rounds(tasks2));
+}