Focus on the most frequent task. It determines the minimum time.
If the most frequent task appears maxCount times, you need at least (maxCount - 1) × (n + 1) intervals just for that task and its cooldowns, plus 1 more for the final occurrence.
But multiple tasks might share the max frequency. Count how many tasks have maxCount occurrences. Add that to account for parallel scheduling in the last batch.
The answer is max(total tasks, (maxCount - 1) × (n + 1) + numMaxTasks). If there are enough diverse tasks, you might not need any idle time at all.