From 7c60dee83b436e8e8a667bf9f191beced8de4fc3 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Mon, 10 Mar 2025 00:36:13 -0600 Subject: chore: move cpp and rust code to directory --- other/earliest_possible_full_bloom.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 other/earliest_possible_full_bloom.rs (limited to 'other/earliest_possible_full_bloom.rs') diff --git a/other/earliest_possible_full_bloom.rs b/other/earliest_possible_full_bloom.rs new file mode 100644 index 0000000..b8e6444 --- /dev/null +++ b/other/earliest_possible_full_bloom.rs @@ -0,0 +1,20 @@ +struct Solution; + +impl Solution { + pub fn earliest_full_bloom(plant_time: Vec, grow_time: Vec) -> i32 { + let n = plant_time.len(); + let mut plant_data: Vec<(i32, i32)> = plant_time.into_iter().zip(grow_time.into_iter()).collect(); + plant_data.sort_by(|a,b| b.1.cmp(&a.1)); + let (mut free_time, mut max_bloom_time) = (0,0); + for i in 0..n { + free_time += plant_data[i].0; + max_bloom_time = max_bloom_time.max(free_time + plant_data[i].1); + } + max_bloom_time + } +} + +fn main() { + let (plant_time, grow_time) = (vec![1,4,3], vec![2,3,1]); + print!("{}", Solution::earliest_full_bloom(plant_time, grow_time)); +} -- cgit v1.2.3