Variation of Task Scheduler problem 🤠

Original problem : https://leetcode.com/problems/task-scheduler/

Consider that you are given an additional constraint on this problem which asks you to assume a cooldown period which can vary according to the task.

Instead of a single integer n you are given a map which represents the task along with it's cooldown duration.

  • Input seq : ABAB

  • cool down time :

      coolDownMap.put('A',3);
      coolDownMap.put('B',2);
      coolDownMap.put('C',1);
      coolDownMap.put('D',2);
      

    Here 1st A will execute in 1 unit of time . Total Time = 1

    • 2nd B will execute in 1 unit .Total time = prev_total + 1 = 2
    • 3rd A = 2 + (3-1) + 1 = 5
    • 4th B 5+1 = 6
    • Output : 6

Seq AAA : output ->9

Seq ABCD : output -> 4

Any ideas on this one would be really helpful :)

Comments (2)