Earliest Possible Day of Full Bloom - Problem
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 thei-thseed. Every day, you can work on planting exactly one seed. You do not have to work on planting the same seed on consecutive days, but the planting of a seed is not complete until you have workedplantTime[i]days on planting it in total.growTime[i]is the number of full days it takes thei-thseed to grow after being completely planted. After the last day of its growth, the flower blooms and stays bloomed forever.
From the beginning of day 0, you can plant the seeds in any order.
Return the earliest possible day where all seeds are blooming.
Input & Output
Example 1 — Basic Case
$
Input:
plantTime = [1,4,3], growTime = [2,3,1]
›
Output:
9
💡 Note:
Optimal order is to plant seed 1 (grow time 3), then seed 0 (grow time 2), then seed 2 (grow time 1). Plant seed 1 on days 0-3 (completes day 4), blooms day 7. Plant seed 0 on day 4 (completes day 5), blooms day 7. Plant seed 2 on days 5-7 (completes day 8), blooms day 9. All seeds bloom by day 9.
Example 2 — Equal Plant Times
$
Input:
plantTime = [1,2,3,2], growTime = [2,1,2,1]
›
Output:
9
💡 Note:
Sort by grow time descending: seeds 0,2 (grow=2), then seeds 1,3 (grow=1). Plant in order [0,2,1,3]. Seed 0: plant days 0, blooms day 1+2=3. Seed 2: plant days 1-3, blooms day 4+2=6. Seed 1: plant days 4-5, blooms day 6+1=7. Seed 3: plant days 6-7, blooms day 8+1=9.
Example 3 — Single Seed
$
Input:
plantTime = [1], growTime = [1]
›
Output:
2
💡 Note:
Only one seed: plant it on day 0, completes day 1, blooms on day 1+1=2.
Constraints
- n == plantTime.length == growTime.length
- 1 ≤ n ≤ 105
- 1 ≤ plantTime[i], growTime[i] ≤ 104
Visualization
Tap to expand
Understanding the Visualization
1
Input
Two arrays: plant times and grow times for each seed
2
Strategy
Sort by grow time (longest first) to optimize scheduling
3
Output
Earliest day when all seeds have bloomed
Key Takeaway
🎯 Key Insight: Plant seeds with longest grow times first to minimize total completion time
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code