Skip to content

Generate PR for codedecks by solving any STACK/QUEUE section problem of LeetCode #90 #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Python/621-Task-Scheduler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
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),
is that there must be at least n units of time between any two same tasks.


Memory ->14.4MB
runtime ->412ms




"""


class Solution:
def leastInterval(self, tasks: List[str], n: int) -> int:
counter=Counter(tasks)
freq=sorted(list(counter.values()))

max_idle=freq.pop()
total=(max_idle-1)*n

while freq and total>0:
total=total-min(max_idle-1,freq.pop())

total=max(0,total)
return len(tasks) + total
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
| --- | ------------------------------------------------------------------------------- | --------------------------------------- | ------ | ------ | ---------- | --------------------- | ---- |
| 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls/) | [C++](./C++/Number-of-Recent-Calls.cpp) | _O(1)_ | _O(1)_ | Easy | Queue, Sliding Window |
| 641 | [Design Circular Deque](https://leetcode.com/problems/design-circular-deque/) | [Java](./Java/design-circular-deque.java/) | _O(n)_ | _O(n)_ | Medium | Queue, Design |
| 621 | [Task Scheduler ](https://leetcode.com/problems/task-scheduler/) | [Python](./Python/621-Task-Scheduler.py/) | _O(n)_| _O(n)_| Medium | Queue

<br/>
<div align="right">
Expand Down