Task Scheduler Leetcode

preview_player
Показать описание
This Video explains the problem task scheduler from Leetcode. The approach uses an array to store the given tasks and compute the time needed for solving them.

Рекомендации по теме
Комментарии
Автор

["A", "A", "B", "B", "C", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
30
Output: 29
expected: 34
Failed.
Because of this line j = j == 0? 25 : j - 1; The counter[j] can't be circled back because duplicate task is not allowed within this n + 1 time interval.

chengwl
Автор

I think the time complexity is O(n) as the array is of size 26 regardless of size of input and so the sort function takes O(26log26) = O(1). Therefore the incrementing of the array for each letter initially is the bound of the algorithm at O(n)

SharKh
Автор

Can you tell clearly why time is time+(n-i+1)

visharthigee
visit shbcf.ru