#2136
Hard Algorithms Earliest possible day of full bloom
Array Greedy Sorting
71.2% acceptance
Feb 25, 2026
1672
86
You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed takes time and so does the growth of a seed. You are given two 0-indexed integer arrays plantTime and growTime, of length n each:
plantTime[i] is the number of full days it takes you to plant the ith seed.
growTime[i] is the number of full days it takes the ith seed to grow after being completely planted.
From the beginning of day 0, you can plant the seeds in any order.
Return the earliest possible day where all seeds are blooming.
Solution
Rust
Time O(n log n)
Space O(1)
impl Solution {
pub fn earliest_full_bloom(plant_time: Vec<i32>, grow_time: Vec<i32>) -> i32 {
let n = plant_time.len();
let mut idx: Vec<usize> = (0..n).collect();
// Sort by growTime descending: plant slow-growing flowers first
idx.sort_by(|&a, &b| grow_time[b].cmp(&grow_time[a]));
let mut day = 0i32;
let mut ans = 0i32;
for i in idx {
day += plant_time[i];
// Bloom day = day (finish planting) + growTime[i]
ans = ans.max(day + grow_time[i]);
}
ans
}
}