Skip to content

Commit 3042609

Browse files
authored
Update 0621-task-scheduler.md
1 parent 170863a commit 3042609

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

dsa-solutions/lc-solutions/0600-0699/0621-task-scheduler.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ With a cooling interval of 1, you can repeat a task after just one other task.
4343

4444
### Constraints
4545

46-
- $1 <= tasks.length <= 10^4$
46+
- $1 \leq \text{tasks.length} \leq 10^4$
4747
- `tasks[i]` is an uppercase English letter.
48-
- $0 <= n <= 100$
48+
- $0 \leq n \leq 100$
4949

5050
## Solution for Task Scheduler
5151

@@ -268,9 +268,9 @@ class Solution:
268268
269269
### Space Complexity: $O(1)$
270270

271-
> **Reason**: The space complexity is mainly determined by the frequency array and the priority queue. The frequency array has a constant size of 26, and the priority queue can have a maximum size of 26 when all distinct tasks are present. Therefore, the overall space complexity is O(1) or O(26), which is considered constant.
271+
> **Reason**: The space complexity is mainly determined by the frequency array and the priority queue. The frequency array has a constant size of 26, and the priority queue can have a maximum size of 26 when all distinct tasks are present. Therefore, the overall space complexity is $O(1)$ or $O(26)$, which is considered constant.
272272
273-
### Approach #2 Filling the Slots and Sorting
273+
### Approach 2 Filling the Slots and Sorting
274274
#### Intuition
275275
We need to find the minimum time required to complete all tasks given the constraint that at least `n` units of time must elapse between two identical tasks. To minimize the time, we should first consider scheduling the most frequent tasks so that they are separated by `n` units of time. Then, we can fill the idle slots with the remaining tasks.
276276

@@ -403,13 +403,16 @@ class Solution:
403403
### Space Complexity: $O(1)$
404404

405405
> **Reason**: The frequency array has a size of 26.
406-
>
407-
> Note that some extra space is used when we sort arrays in place. The space complexity of the sorting algorithm depends on the programming language.
408-
>
409-
> - In Python, the sort method sorts a list using the Timsort algorithm which is a combination of Merge Sort and Insertion Sort and has O(N) additional space.
410-
> - In Java, Arrays.sort() is implemented using a variant of the Quick Sort algorithm which has a space complexity of O(log⁡N) for sorting two arrays.
411-
> - In C++, the sort() function is implemented as a hybrid of Quick Sort, Heap Sort, and Insertion Sort, with a worse-case space complexity of O(log⁡N).
412-
> We sort the frequency array, which has a size of 26. The space used for sorting takes O(26) or O(log⁡26), which is constant, so the space complexity of the algorithm is O(26), which is constant, i.e. O(1).
406+
407+
:::note
408+
Some extra space is used when we sort arrays in place. The space complexity of the sorting algorithm depends on the programming language.
409+
410+
- In Python, the sort method sorts a list using the Timsort algorithm which is a combination of Merge Sort and Insertion Sort and has $O(N)$ additional space.
411+
- In Java, Arrays.sort() is implemented using a variant of the Quick Sort algorithm which has a space complexity of $O(log⁡N)$ for sorting two arrays.
412+
- In C++, the sort() function is implemented as a hybrid of Quick Sort, Heap Sort, and Insertion Sort, with a worse-case space complexity of $O(log⁡N)$.
413+
414+
We sort the frequency array, which has a size of 26. The space used for sorting takes $O(26)$ or $O(log⁡26)$, which is constant, so the space complexity of the algorithm is $O(26)$, which is constant, i.e. $O(1)$.
415+
:::
413416

414417
## References
415418

0 commit comments

Comments
 (0)