DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Heap

Task Scheduler

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Task Scheduler** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Max-heap + cooldown idle slots or formula **Edge Cases to Consider:** - (1) n = 0 (no cooldown) - (2) All same tasks - (3) k = 1 task

Examples

Example 1
Input: ['A','A','A','B','B','B'], 2
Output: 8
Explanation: Classic
Example 2
Input: ['A','A','A','B','B','B'], 0
Output: 6
Explanation: No cooldown
Example 3
Input: ['A','A','A','A','A','A','B','C','D','E','F','G'], 2
Output: 16

Constraints

  • ▪Input arguments are within valid ranges
  • ▪Optimize for execution speed
  • ▪Handle null/empty inputs gracefully

Watch Out For Edge Cases

  • ▪n = 0 (no cooldown)
  • ▪All same tasks
  • ▪k = 1 task
Frequently Asked At
AmazonGoogleMicrosoftMetaAdobe