From b9c7a1732f114314704355b0a0f73d41ccaa1540 Mon Sep 17 00:00:00 2001 From: Aryan Mankame <87220756+AryanMankame@users.noreply.github.com> Date: Tue, 11 Oct 2022 00:52:44 +0530 Subject: [PATCH 01/20] Create longest_valid_paranthesis.py made necessary changes! --- strings/longest_valid_paranthesis.py | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 strings/longest_valid_paranthesis.py diff --git a/strings/longest_valid_paranthesis.py b/strings/longest_valid_paranthesis.py new file mode 100644 index 000000000000..79aa560538e4 --- /dev/null +++ b/strings/longest_valid_paranthesis.py @@ -0,0 +1,32 @@ +def longest_valid_paranthesis(self, s: str) -> int: + """ + Returns the length of the longest valid paranthesis + >>> longest_valid_paranthesis('(()') + 2 + >>> longest_valid_paranthesis(')()())') + 4 + >>> longest_valid_paranthesis('') + 0 + >>> longest_valid_paranthesis(''(())))((()(()()()()) + 8 + """ + stack = [] + preceeding_matched = 0 + res = 0 + for char in s: + if char == "(": + stack.append(preceeding_matched) + preceeding_matched = 0 + else: + if stack: + preceeding_matched += 1 + stack.pop() + else: + res = max(res, preceeding_matched) + preceeding_matched = 0 + + res = max(res, preceeding_matched) + + while stack: + res = max(res, stack.pop()) + + return res * 2 From f1cd3ecc85a62274d1c12394ce14994638b17a43 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 19:28:37 +0000 Subject: [PATCH 02/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/longest_valid_paranthesis.py | 60 ++++++++++++++-------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/strings/longest_valid_paranthesis.py b/strings/longest_valid_paranthesis.py index 79aa560538e4..1791937f61ae 100644 --- a/strings/longest_valid_paranthesis.py +++ b/strings/longest_valid_paranthesis.py @@ -1,32 +1,32 @@ def longest_valid_paranthesis(self, s: str) -> int: - """ - Returns the length of the longest valid paranthesis - >>> longest_valid_paranthesis('(()') - 2 - >>> longest_valid_paranthesis(')()())') - 4 - >>> longest_valid_paranthesis('') - 0 - >>> longest_valid_paranthesis(''(())))((()(()()()()) - 8 - """ - stack = [] - preceeding_matched = 0 - res = 0 - for char in s: - if char == "(": - stack.append(preceeding_matched) - preceeding_matched = 0 + """ + Returns the length of the longest valid paranthesis + >>> longest_valid_paranthesis('(()') + 2 + >>> longest_valid_paranthesis(')()())') + 4 + >>> longest_valid_paranthesis('') + 0 + >>> longest_valid_paranthesis(''(())))((()(()()()()) + 8 + """ + stack = [] + preceeding_matched = 0 + res = 0 + for char in s: + if char == "(": + stack.append(preceeding_matched) + preceeding_matched = 0 + else: + if stack: + preceeding_matched += 1 + stack.pop() else: - if stack: - preceeding_matched += 1 + stack.pop() - else: - res = max(res, preceeding_matched) - preceeding_matched = 0 - - res = max(res, preceeding_matched) - - while stack: - res = max(res, stack.pop()) - - return res * 2 + res = max(res, preceeding_matched) + preceeding_matched = 0 + + res = max(res, preceeding_matched) + + while stack: + res = max(res, stack.pop()) + + return res * 2 From 8ba36a16868fe602871ad80ff2cacfcd843cf0ab Mon Sep 17 00:00:00 2001 From: Aryan Mankame <87220756+AryanMankame@users.noreply.github.com> Date: Tue, 11 Oct 2022 01:06:51 +0530 Subject: [PATCH 03/20] Update longest_valid_paranthesis.py added necessary changes! --- strings/longest_valid_paranthesis.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/strings/longest_valid_paranthesis.py b/strings/longest_valid_paranthesis.py index 1791937f61ae..1a9bbd9392cb 100644 --- a/strings/longest_valid_paranthesis.py +++ b/strings/longest_valid_paranthesis.py @@ -23,10 +23,11 @@ def longest_valid_paranthesis(self, s: str) -> int: else: res = max(res, preceeding_matched) preceeding_matched = 0 - res = max(res, preceeding_matched) while stack: res = max(res, stack.pop()) - return res * 2 +if __name__ == "__main__": + from doctest import testmod + testmod() From 4ef0c9a3a4c7f252e0f33bcd523d44ac85121d2d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 19:39:34 +0000 Subject: [PATCH 04/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/longest_valid_paranthesis.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/strings/longest_valid_paranthesis.py b/strings/longest_valid_paranthesis.py index 1a9bbd9392cb..02b5cb49bb17 100644 --- a/strings/longest_valid_paranthesis.py +++ b/strings/longest_valid_paranthesis.py @@ -28,6 +28,9 @@ def longest_valid_paranthesis(self, s: str) -> int: while stack: res = max(res, stack.pop()) return res * 2 + + if __name__ == "__main__": from doctest import testmod + testmod() From 38e2790f1b996c077522f712af27a521327b3df6 Mon Sep 17 00:00:00 2001 From: Aryan Mankame <87220756+AryanMankame@users.noreply.github.com> Date: Tue, 11 Oct 2022 01:22:31 +0530 Subject: [PATCH 05/20] Update longest_valid_paranthesis.py added the necessary changes! --- strings/longest_valid_paranthesis.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/strings/longest_valid_paranthesis.py b/strings/longest_valid_paranthesis.py index 02b5cb49bb17..7a278b7fd4e6 100644 --- a/strings/longest_valid_paranthesis.py +++ b/strings/longest_valid_paranthesis.py @@ -1,13 +1,13 @@ -def longest_valid_paranthesis(self, s: str) -> int: +def longest_valid_parenthesis(self, s: str) -> int: """ Returns the length of the longest valid paranthesis - >>> longest_valid_paranthesis('(()') + >>> longest_valid_parenthesis('(()') 2 - >>> longest_valid_paranthesis(')()())') + >>> longest_valid_parenthesis(')()())') 4 - >>> longest_valid_paranthesis('') + >>> longest_valid_parenthesis('') 0 - >>> longest_valid_paranthesis(''(())))((()(()()()()) + >>> longest_valid_parenthesis(''(())))((()(()()()()) 8 """ stack = [] @@ -28,9 +28,6 @@ def longest_valid_paranthesis(self, s: str) -> int: while stack: res = max(res, stack.pop()) return res * 2 - - if __name__ == "__main__": from doctest import testmod - testmod() From bc567747f12c8a1d816cede784c47efc8795a5df Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 19:54:32 +0000 Subject: [PATCH 06/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/longest_valid_paranthesis.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/strings/longest_valid_paranthesis.py b/strings/longest_valid_paranthesis.py index 7a278b7fd4e6..39d02d3a9383 100644 --- a/strings/longest_valid_paranthesis.py +++ b/strings/longest_valid_paranthesis.py @@ -28,6 +28,9 @@ def longest_valid_parenthesis(self, s: str) -> int: while stack: res = max(res, stack.pop()) return res * 2 + + if __name__ == "__main__": from doctest import testmod + testmod() From cb0b8c506813abf41092b6687ea847d410d27b72 Mon Sep 17 00:00:00 2001 From: Aryan Mankame <87220756+AryanMankame@users.noreply.github.com> Date: Tue, 11 Oct 2022 01:28:12 +0530 Subject: [PATCH 07/20] Rename longest_valid_paranthesis.py to longest_valid_parenthesis.py added necessary changes! --- ...{longest_valid_paranthesis.py => longest_valid_parenthesis.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename strings/{longest_valid_paranthesis.py => longest_valid_parenthesis.py} (100%) diff --git a/strings/longest_valid_paranthesis.py b/strings/longest_valid_parenthesis.py similarity index 100% rename from strings/longest_valid_paranthesis.py rename to strings/longest_valid_parenthesis.py From 5fc6444426ea0d5470a9624d8b2c94138581715c Mon Sep 17 00:00:00 2001 From: Aryan Mankame <87220756+AryanMankame@users.noreply.github.com> Date: Tue, 11 Oct 2022 01:36:15 +0530 Subject: [PATCH 08/20] Update longest_valid_parenthesis.py added necessary changes --- strings/longest_valid_parenthesis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/longest_valid_parenthesis.py b/strings/longest_valid_parenthesis.py index 39d02d3a9383..d2219bdf7966 100644 --- a/strings/longest_valid_parenthesis.py +++ b/strings/longest_valid_parenthesis.py @@ -1,6 +1,6 @@ def longest_valid_parenthesis(self, s: str) -> int: """ - Returns the length of the longest valid paranthesis + Returns the length of the longest valid parenthesis >>> longest_valid_parenthesis('(()') 2 >>> longest_valid_parenthesis(')()())') From d929b71c0187054c3143a7c56e0dfa91d58f2f72 Mon Sep 17 00:00:00 2001 From: Aryan Mankame <87220756+AryanMankame@users.noreply.github.com> Date: Tue, 11 Oct 2022 02:00:48 +0530 Subject: [PATCH 09/20] Update longest_valid_parenthesis.py added longest_valid_parenthesis.py --- strings/longest_valid_parenthesis.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/strings/longest_valid_parenthesis.py b/strings/longest_valid_parenthesis.py index d2219bdf7966..857cf4827d61 100644 --- a/strings/longest_valid_parenthesis.py +++ b/strings/longest_valid_parenthesis.py @@ -5,8 +5,8 @@ def longest_valid_parenthesis(self, s: str) -> int: 2 >>> longest_valid_parenthesis(')()())') 4 - >>> longest_valid_parenthesis('') - 0 + >>> longest_valid_parenthesis('(()()()()))') + 10 >>> longest_valid_parenthesis(''(())))((()(()()()()) 8 """ @@ -24,13 +24,9 @@ def longest_valid_parenthesis(self, s: str) -> int: res = max(res, preceeding_matched) preceeding_matched = 0 res = max(res, preceeding_matched) - while stack: res = max(res, stack.pop()) return res * 2 - - if __name__ == "__main__": from doctest import testmod - testmod() From ec09f3f54d643dfa584668c3ec8f8e38881b9384 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:31:51 +0000 Subject: [PATCH 10/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/longest_valid_parenthesis.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/strings/longest_valid_parenthesis.py b/strings/longest_valid_parenthesis.py index 857cf4827d61..35f333c33cc3 100644 --- a/strings/longest_valid_parenthesis.py +++ b/strings/longest_valid_parenthesis.py @@ -27,6 +27,9 @@ def longest_valid_parenthesis(self, s: str) -> int: while stack: res = max(res, stack.pop()) return res * 2 + + if __name__ == "__main__": from doctest import testmod + testmod() From b12a42ee43277fdc7b21da03b93feef1f305a000 Mon Sep 17 00:00:00 2001 From: Aryan Mankame <87220756+AryanMankame@users.noreply.github.com> Date: Tue, 11 Oct 2022 02:13:38 +0530 Subject: [PATCH 11/20] Update longest_valid_parenthesis.py added longest_valid_parenthesis.py --- strings/longest_valid_parenthesis.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/strings/longest_valid_parenthesis.py b/strings/longest_valid_parenthesis.py index 35f333c33cc3..d652401d4950 100644 --- a/strings/longest_valid_parenthesis.py +++ b/strings/longest_valid_parenthesis.py @@ -27,9 +27,6 @@ def longest_valid_parenthesis(self, s: str) -> int: while stack: res = max(res, stack.pop()) return res * 2 - - if __name__ == "__main__": - from doctest import testmod - - testmod() + s = input() + print(longest_valid_parenthesis(s)) From 349190100e9fadab3970c3f835222b2508bb600d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:44:29 +0000 Subject: [PATCH 12/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/longest_valid_parenthesis.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/strings/longest_valid_parenthesis.py b/strings/longest_valid_parenthesis.py index d652401d4950..c55aa22b2638 100644 --- a/strings/longest_valid_parenthesis.py +++ b/strings/longest_valid_parenthesis.py @@ -27,6 +27,8 @@ def longest_valid_parenthesis(self, s: str) -> int: while stack: res = max(res, stack.pop()) return res * 2 + + if __name__ == "__main__": s = input() print(longest_valid_parenthesis(s)) From d3abc71174a095a1a6375330017df4ccfc79ac45 Mon Sep 17 00:00:00 2001 From: Aryan Mankame <87220756+AryanMankame@users.noreply.github.com> Date: Tue, 11 Oct 2022 02:16:41 +0530 Subject: [PATCH 13/20] Update longest_valid_parenthesis.py added longest_valid_parenthesis.py --- strings/longest_valid_parenthesis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/longest_valid_parenthesis.py b/strings/longest_valid_parenthesis.py index c55aa22b2638..a99f75c433cc 100644 --- a/strings/longest_valid_parenthesis.py +++ b/strings/longest_valid_parenthesis.py @@ -1,4 +1,4 @@ -def longest_valid_parenthesis(self, s: str) -> int: +def longest_valid_parenthesis(s: str) -> int: """ Returns the length of the longest valid parenthesis >>> longest_valid_parenthesis('(()') From 8441f5e850ad86ea77f6aed370df7355af93d1a6 Mon Sep 17 00:00:00 2001 From: Aryan Mankame <87220756+AryanMankame@users.noreply.github.com> Date: Tue, 11 Oct 2022 02:25:57 +0530 Subject: [PATCH 14/20] Update longest_valid_parenthesis.py added longest_valid_parenthesis.py --- strings/longest_valid_parenthesis.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/strings/longest_valid_parenthesis.py b/strings/longest_valid_parenthesis.py index a99f75c433cc..3e74d1cc29eb 100644 --- a/strings/longest_valid_parenthesis.py +++ b/strings/longest_valid_parenthesis.py @@ -1,6 +1,8 @@ def longest_valid_parenthesis(s: str) -> int: """ Returns the length of the longest valid parenthesis + :param s: + :return: int >>> longest_valid_parenthesis('(()') 2 >>> longest_valid_parenthesis(')()())') From 3fd11fe6088b6ef7068ebd442a5e853c8045049b Mon Sep 17 00:00:00 2001 From: Aryan Mankame <87220756+AryanMankame@users.noreply.github.com> Date: Tue, 11 Oct 2022 02:39:46 +0530 Subject: [PATCH 15/20] Update longest_valid_parenthesis.py added longest_valid_parenthesis.py --- strings/longest_valid_parenthesis.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/strings/longest_valid_parenthesis.py b/strings/longest_valid_parenthesis.py index 3e74d1cc29eb..a99f75c433cc 100644 --- a/strings/longest_valid_parenthesis.py +++ b/strings/longest_valid_parenthesis.py @@ -1,8 +1,6 @@ def longest_valid_parenthesis(s: str) -> int: """ Returns the length of the longest valid parenthesis - :param s: - :return: int >>> longest_valid_parenthesis('(()') 2 >>> longest_valid_parenthesis(')()())') From 5d1ee491fb3ac59e31b3cc27201674480a608889 Mon Sep 17 00:00:00 2001 From: Aryan Mankame <87220756+AryanMankame@users.noreply.github.com> Date: Tue, 11 Oct 2022 02:46:26 +0530 Subject: [PATCH 16/20] Create sleepsort.py added sleepsort.py --- sorts/sleepsort.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 sorts/sleepsort.py diff --git a/sorts/sleepsort.py b/sorts/sleepsort.py new file mode 100644 index 000000000000..87dc2bd3db44 --- /dev/null +++ b/sorts/sleepsort.py @@ -0,0 +1,11 @@ +import thread +from time import sleep +items = [] +n = int(input()) +for i in range(0,n): + a = int(input()) + items.append(a) +def sleep_sort(i): + sleep(i) + print i +[thread.start_new_thread(sleep_sort, (i,)) for i in items] From 7961ea3339ad5a4dd9e7e1648ac6e9b421d44766 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 21:17:30 +0000 Subject: [PATCH 17/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/sleepsort.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sorts/sleepsort.py b/sorts/sleepsort.py index 87dc2bd3db44..e5bd1a3a6039 100644 --- a/sorts/sleepsort.py +++ b/sorts/sleepsort.py @@ -1,5 +1,7 @@ -import thread from time import sleep + +import thread + items = [] n = int(input()) for i in range(0,n): From 569159633fb47d9b0a92ea20567cb24c087d8842 Mon Sep 17 00:00:00 2001 From: Aryan Mankame <87220756+AryanMankame@users.noreply.github.com> Date: Tue, 11 Oct 2022 02:50:41 +0530 Subject: [PATCH 18/20] Update sleepsort.py --- sorts/sleepsort.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sorts/sleepsort.py b/sorts/sleepsort.py index e5bd1a3a6039..d022d0197bdf 100644 --- a/sorts/sleepsort.py +++ b/sorts/sleepsort.py @@ -8,6 +8,6 @@ a = int(input()) items.append(a) def sleep_sort(i): - sleep(i) - print i + sleep(i) + print i [thread.start_new_thread(sleep_sort, (i,)) for i in items] From ad9424831c6fb61fd71b92379e74d596cadbc6d9 Mon Sep 17 00:00:00 2001 From: Aryan Mankame <87220756+AryanMankame@users.noreply.github.com> Date: Tue, 11 Oct 2022 02:54:56 +0530 Subject: [PATCH 19/20] Update sleepsort.py --- sorts/sleepsort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorts/sleepsort.py b/sorts/sleepsort.py index d022d0197bdf..91d1f78c5e43 100644 --- a/sorts/sleepsort.py +++ b/sorts/sleepsort.py @@ -9,5 +9,5 @@ items.append(a) def sleep_sort(i): sleep(i) - print i + print(i) [thread.start_new_thread(sleep_sort, (i,)) for i in items] From 1993cb9fed2e7f7d0c321cc178b2af519700cf06 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 21:27:01 +0000 Subject: [PATCH 20/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/sleepsort.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sorts/sleepsort.py b/sorts/sleepsort.py index 91d1f78c5e43..267b160cf3b3 100644 --- a/sorts/sleepsort.py +++ b/sorts/sleepsort.py @@ -4,10 +4,14 @@ items = [] n = int(input()) -for i in range(0,n): - a = int(input()) - items.append(a) +for i in range(0, n): + a = int(input()) + items.append(a) + + def sleep_sort(i): - sleep(i) - print(i) + sleep(i) + print(i) + + [thread.start_new_thread(sleep_sort, (i,)) for i in items]