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 the i-th seed. 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 worked plantTime[i] days on planting it in total.
  • growTime[i] is the number of full days it takes the i-th seed 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
Earliest Possible Day of Full BloomInput: plantTime=[1,4,3], growTime=[2,3,1]Seeds with Plant/Grow Times:Seed 0P:1 G:2Seed 1P:4 G:3Seed 2P:3 G:1Optimal Strategy: Plant by grow time (longest first)1st: Seed 1 (G:3)2nd: Seed 0 (G:2)3rd: Seed 2 (G:1)Result: Day 9All flowers bloom by day 9 with optimal planting order
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
Asked in
Google 15 Amazon 12 Microsoft 8 Meta 6
28.5K Views
Medium Frequency
~25 min Avg. Time
845 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen