> For the complete documentation index, see [llms.txt](https://jaywin.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jaywin.gitbook.io/leetcode/topics/greedy.md).

# 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).

* [0358. Rearrange String k Distance Apart](https://github.com/jaywinhuang/leetcode/blob/master/topics/0358-rearrange-string-k-distance-apart.md)

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

* [0621. Task Scheduler](https://github.com/jaywinhuang/leetcode/blob/master/topics/0621-task-scheduler.md)
* [0767. Reorganize String](https://github.com/jaywinhuang/leetcode/blob/master/topics/0767-reorganize-string.md)
