You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dsa-solutions/lc-solutions/0600-0699/0621-task-scheduler.md
+14-11Lines changed: 14 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -43,9 +43,9 @@ With a cooling interval of 1, you can repeat a task after just one other task.
43
43
44
44
### Constraints
45
45
46
-
- $1 <= tasks.length <= 10^4$
46
+
- $1 \leq \text{tasks.length} \leq 10^4$
47
47
-`tasks[i]` is an uppercase English letter.
48
-
- $0 <= n <= 100$
48
+
- $0 \leq n \leq 100$
49
49
50
50
## Solution for Task Scheduler
51
51
@@ -268,9 +268,9 @@ class Solution:
268
268
269
269
### Space Complexity: $O(1)$
270
270
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.
272
272
273
-
### Approach #2 Filling the Slots and Sorting
273
+
### Approach 2 Filling the Slots and Sorting
274
274
#### Intuition
275
275
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.
276
276
@@ -403,13 +403,16 @@ class Solution:
403
403
### Space Complexity: $O(1)$
404
404
405
405
> **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(logN) 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(logN).
412
-
> We sort the frequency array, which has a size of 26. The space used for sorting takes O(26) or O(log26), 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(logN)$ 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(logN)$.
413
+
414
+
We sort the frequency array, which has a size of 26. The space used for sorting takes $O(26)$ or $O(log26)$, which is constant, so the space complexity of the algorithm is $O(26)$, which is constant, i.e. $O(1)$.
0 commit comments