From 81107c81d3825610fbc60f346b4c04f085f2f678 Mon Sep 17 00:00:00 2001
From: heyyviv <56256802+heyyviv@users.noreply.github.com>
Date: Sat, 17 Oct 2020 11:15:38 +0530
Subject: [PATCH 1/5] Generate PR for codedecks by solving any STACK/QUEUE
section problem of LeetCode #90
---
Python/Valid-Parentheses.py | 41 +++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100644 Python/Valid-Parentheses.py
diff --git a/Python/Valid-Parentheses.py b/Python/Valid-Parentheses.py
new file mode 100644
index 00000000..b5783795
--- /dev/null
+++ b/Python/Valid-Parentheses.py
@@ -0,0 +1,41 @@
+"""
+link - https://leetcode.com/problems/valid-parentheses
+
+Given a string s containing just the characters '(', ')', '{', '}', '[' and ']',
+determine if the input string is valid.
+
+
+"""
+
+
+class Solution:
+ def isValid(self, s: str) -> bool:
+ if len(s)==0:
+ return True
+ ans=[]
+ if s[0] in "]})" :
+ return False
+
+ for i in range(0,len(s)):
+ try:
+
+ if s[i] in "{([":
+ ans.append(s[i])
+ elif s[i]=='}':
+ k=ans.pop()
+ if k!='{':
+ return False
+ elif s[i]==']':
+ k=ans.pop()
+ if k!='[':
+ return False
+ elif s[i]==')':
+ k=ans.pop()
+ if k!='(':
+ return False
+ except:
+ return False
+ if len(ans)==0:
+ return True
+ else:
+ return False
From d127c238866107c8aeebe32a31b4fae03d2bc9b7 Mon Sep 17 00:00:00 2001
From: heyyviv <56256802+heyyviv@users.noreply.github.com>
Date: Sat, 17 Oct 2020 11:20:38 +0530
Subject: [PATCH 2/5] Generate PR for codedecks by solving any STACK/QUEUE
section problem of LeetCode #90
---
Python/Valid-Parentheses.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Python/Valid-Parentheses.py b/Python/Valid-Parentheses.py
index b5783795..5db3e376 100644
--- a/Python/Valid-Parentheses.py
+++ b/Python/Valid-Parentheses.py
@@ -4,6 +4,10 @@
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']',
determine if the input string is valid.
+speed - 16 ms
+memory - 13.9 MB
+
+time complexity - O(n)
"""
From e7b808442f26a2c367fb9723f78624b37db18753 Mon Sep 17 00:00:00 2001
From: heyyviv <56256802+heyyviv@users.noreply.github.com>
Date: Sat, 17 Oct 2020 11:24:34 +0530
Subject: [PATCH 3/5] Generate PR for codedecks by solving any STACK/QUEUE
section problem of LeetCode #90
---
Python/Valid-Parentheses.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Python/Valid-Parentheses.py b/Python/Valid-Parentheses.py
index 5db3e376..3f752f6c 100644
--- a/Python/Valid-Parentheses.py
+++ b/Python/Valid-Parentheses.py
@@ -8,6 +8,9 @@
memory - 13.9 MB
time complexity - O(n)
+space Complexity - O(n)
+
+difficulty - easy
"""
From 91906138fc377f68c7c55ba9359d80a0a1d3e076 Mon Sep 17 00:00:00 2001
From: heyyviv <56256802+heyyviv@users.noreply.github.com>
Date: Sat, 17 Oct 2020 20:52:48 +0530
Subject: [PATCH 4/5] Generate PR for codedecks by solving any STACK/QUEUE
section problem of LeetCode #90
---
Python/621-Task-Scheduler.py | 32 ++++++++++++++++++++++++
Python/Valid-Parentheses.py | 48 ------------------------------------
2 files changed, 32 insertions(+), 48 deletions(-)
create mode 100644 Python/621-Task-Scheduler.py
delete mode 100644 Python/Valid-Parentheses.py
diff --git a/Python/621-Task-Scheduler.py b/Python/621-Task-Scheduler.py
new file mode 100644
index 00000000..730585af
--- /dev/null
+++ b/Python/621-Task-Scheduler.py
@@ -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
diff --git a/Python/Valid-Parentheses.py b/Python/Valid-Parentheses.py
deleted file mode 100644
index 3f752f6c..00000000
--- a/Python/Valid-Parentheses.py
+++ /dev/null
@@ -1,48 +0,0 @@
-"""
-link - https://leetcode.com/problems/valid-parentheses
-
-Given a string s containing just the characters '(', ')', '{', '}', '[' and ']',
-determine if the input string is valid.
-
-speed - 16 ms
-memory - 13.9 MB
-
-time complexity - O(n)
-space Complexity - O(n)
-
-difficulty - easy
-
-"""
-
-
-class Solution:
- def isValid(self, s: str) -> bool:
- if len(s)==0:
- return True
- ans=[]
- if s[0] in "]})" :
- return False
-
- for i in range(0,len(s)):
- try:
-
- if s[i] in "{([":
- ans.append(s[i])
- elif s[i]=='}':
- k=ans.pop()
- if k!='{':
- return False
- elif s[i]==']':
- k=ans.pop()
- if k!='[':
- return False
- elif s[i]==')':
- k=ans.pop()
- if k!='(':
- return False
- except:
- return False
- if len(ans)==0:
- return True
- else:
- return False
From 3f9576bb3395ff48398181bf4b301ab955d4a0b4 Mon Sep 17 00:00:00 2001
From: Vivek Das <56256802+heyyviv@users.noreply.github.com>
Date: Sun, 18 Oct 2020 18:36:08 +0530
Subject: [PATCH 5/5] Update README.md
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index c2492d72..64090209 100644
--- a/README.md
+++ b/README.md
@@ -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