You are given a list of product IDs products, where products[i] is the product that must be produced at step i, and an integer space representing a required cooling period.
Rules:
-
You can produce at most one product per day.
-
The products must be produced in the given order.
-
After producing a product with ID
x
, you must wait at least
space
full days before producing product
x
again.
-
During waiting days, you may either produce other products (if they are next in order and valid to produce) or stay idle.
Write a function that returns the minimum number of days needed to produce all products.
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
So the minimum total number of days is 6.