Greedy

Task scheduler problem

  1. Intuitive: construct string from left to right. Use priority queue to firstly consume most frequent char. When a char is used, it has to wait k time to join the pool again. O(Nlog26) time -> O(N).

  1. Visualization: get most frequent char, fill each slot, e.g. A B ? ? A B ? ? A B

Last updated