Dsa
Sliding Window
Easy
Consecutive Task Scheduler
You are managing a task scheduler where tasks need to be scheduled with specific time gaps. Given a list of tasks and an integer 'n' representing the minimum number of days to wait between the same task, find the minimum number of total days required to finish all tasks.
Write a function that takes a list of tasks and an integer n, and returns the minimum number of days needed to complete all tasks while maintaining the required gaps.
Input Format:
- The first line contains an integer t (1 ≤ t ≤ 10^4), the number of tasks.
- The next line contains t space-separated strings representing tasks (e.g., "A B C A D A").
- The last line contains an integer n (0 ≤ n < t).
Output Format:
- Output a single integer, the total minimum number of days to complete all tasks.
Example:
Input:
6
A B C A D A
2
Output:
7
In this example, to complete all tasks, we must schedule the second A after 2 different tasks are completed, giving a total of 7 days.
Key concepts
sliding_windowgreedyarray
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now