Earliest Possible Day of Full Bloom — LeetCode 2136 Python Solution
HardGreedyArraySorting
- Problem
- #2136
- Pattern
- Greedy
- Reading time
- 2 min
- Source
- leetcode.com
The problem
You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom.
Example
- Input
- plantTime = [1,4,3], growTime = [2,3,1]
- Output
- 9
- Explanation
- The grayed out pots represent planting days, colored pots represent growing days, and the flower represents the day it blooms.
Python solution
Python
class Solution:
def earliestFullBloom(self, plantTime: List[int], growTime: List[int]) -> int:
ans = t = 0
for pt, gt in sorted(zip(plantTime, growTime), key=lambda x: -x[1]):
t += pt
ans = max(ans, t + gt)
return ansComplexity
| Measure | Complexity |
|---|---|
| Time | O(n \log n) |
| Space | O(n), where n is the number of seeds auxiliary |
Pattern: Greedy
Take the locally best option every time — when you can prove that never costs you later. LeetCode 2136. Earliest Possible Day of Full Bloom is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Greedy.
The greedy guide has the Python template for the pattern and the 346 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 2136. Earliest Possible Day of Full Bloom?
- LeetCode 2136. Earliest Possible Day of Full Bloom is rated Hard on LeetCode.
- What is the time complexity of LeetCode 2136. Earliest Possible Day of Full Bloom?
- The Python solution on this page runs in O(n \log n).
- What is the space complexity of LeetCode 2136. Earliest Possible Day of Full Bloom?
- The Python solution on this page uses O(n), where n is the number of seeds auxiliary space.
- What topics does LeetCode 2136. Earliest Possible Day of Full Bloom cover?
- LeetCode 2136. Earliest Possible Day of Full Bloom is tagged Greedy, Array and Sorting on LeetCode.