You are given an ordered list of products to manufacture and a non-negative integer space representing the cooling period.
Each day, you may either:
-
produce the next product in the given order, or
-
stay idle.
If you produce product x on day d, then you cannot produce product x again until at least space full days have passed. In other words, the next valid day to produce the same product is d + space + 1.
Your task is to write a Python function that returns the minimum number of days required to produce all products in the given order.
Example:
-
products = [1, 3, 1, 3, 2]
-
space = 2
Output:
Explanation:
-
Day 1: produce
1
-
Day 2: produce
3
-
Day 3: idle
-
Day 4: produce
1
-
Day 5: produce
3
-
Day 6: produce
2
Function goal:
-
Input:
products: List[int]
,
space: int
-
Output: minimum total number of days needed to finish the schedule.