Skip to content

added sleepsort.py #6959

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

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b9c7a17
Create longest_valid_paranthesis.py
AryanMankame Oct 10, 2022
f1cd3ec
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2022
8ba36a1
Update longest_valid_paranthesis.py
AryanMankame Oct 10, 2022
4ef0c9a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2022
38e2790
Update longest_valid_paranthesis.py
AryanMankame Oct 10, 2022
bc56774
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2022
cb0b8c5
Rename longest_valid_paranthesis.py to longest_valid_parenthesis.py
AryanMankame Oct 10, 2022
5fc6444
Update longest_valid_parenthesis.py
AryanMankame Oct 10, 2022
d929b71
Update longest_valid_parenthesis.py
AryanMankame Oct 10, 2022
ec09f3f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2022
b12a42e
Update longest_valid_parenthesis.py
AryanMankame Oct 10, 2022
3491901
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2022
d3abc71
Update longest_valid_parenthesis.py
AryanMankame Oct 10, 2022
8441f5e
Update longest_valid_parenthesis.py
AryanMankame Oct 10, 2022
3fd11fe
Update longest_valid_parenthesis.py
AryanMankame Oct 10, 2022
5d1ee49
Create sleepsort.py
AryanMankame Oct 10, 2022
7961ea3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2022
5691596
Update sleepsort.py
AryanMankame Oct 10, 2022
ad94248
Update sleepsort.py
AryanMankame Oct 10, 2022
1993cb9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2022
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
17 changes: 17 additions & 0 deletions sorts/sleepsort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from time import sleep

import thread

items = []
n = int(input())
for i in range(0, n):
a = int(input())
items.append(a)


def sleep_sort(i):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file sorts/sleepsort.py, please provide doctest for the function sleep_sort

Please provide return type hint for the function: sleep_sort. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: i

Please provide descriptive name for the parameter: i

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file sorts/sleepsort.py, please provide doctest for the function sleep_sort

Please provide return type hint for the function: sleep_sort. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: i

Please provide descriptive name for the parameter: i

sleep(i)
print(i)


[thread.start_new_thread(sleep_sort, (i,)) for i in items]
34 changes: 34 additions & 0 deletions strings/longest_valid_parenthesis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def longest_valid_parenthesis(s: str) -> int:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide descriptive name for the parameter: s

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide descriptive name for the parameter: s

"""
Returns the length of the longest valid parenthesis
>>> longest_valid_parenthesis('(()')
2
>>> longest_valid_parenthesis(')()())')
4
>>> longest_valid_parenthesis('(()()()()))')
10
>>> longest_valid_parenthesis(''(())))((()(()()()())
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


if __name__ == "__main__":
s = input()
print(longest_valid_parenthesis(s))