# ARTS 035

December 15, 2020

## Review

Patterns of resilience

1. 隔离
2. 舱壁
3. 完整参数检查
4. 松耦合
5. 异步通信
6. 位置透明
7. 事件驱动
8. 无状态
9. 松时间约束
10. 幂等
11. 自包含
12. 控制延迟
13. 超时
14. 熔断
15. 快速失败
16. Fan out & quickest reply
17. 有界队列
18. 限流
19. 监管
20. 监控
21. 错误处理
22. 升级

## Algorithm

Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle.

However, there is a non-negative integer n that represents the cooldown period between two same tasks (the same letter in the array), that is that there must be at least n units of time between any two same tasks.

Return the least number of units of times that the CPU will take to finish all the given tasks.

### Solution

fun leastInterval(tasks: CharArray, n: Int): Int {
val taskCount = HashMap<Char, Int>()
for (char in tasks) {
}

val queue = PriorityQueue<Int>(compareByDescending { it })

var times = 0
while (!queue.isEmpty()) {
val tempTaskList = ArrayList<Int>()
for (i in 0..n) {
if (!queue.isEmpty()) {