Skip to content

Doctest and typing for longest_increasing_subsequence.py #1526

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 4 commits into from
Nov 4, 2019
Merged
Changes from 2 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
28 changes: 19 additions & 9 deletions dynamic_programming/longest_increasing_subsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@
Given an ARRAY, to find the longest and increasing sub ARRAY in that given ARRAY and return it.
Example: [10, 22, 9, 33, 21, 50, 41, 60, 80] as input will return [10, 22, 33, 41, 60, 80] as output
"""


def longestSub(ARRAY): # This function is recursive

from typing import List


def longestSub(ARRAY: List[int]) -> List[int]: # This function is recursive
"""
Some examples
>>> longestSub([10, 22, 9, 33, 21, 50, 41, 60, 80])
[10, 22, 33, 41, 60, 80]
>>> longestSub([4, 8, 7, 5, 1, 12, 2, 3, 9])
[1, 2, 3, 9]
>>> longestSub([9, 8, 7, 6, 5, 7])
[8]
>>> longestSub([1, 1, 1])
[1, 1, 1]
"""
ARRAY_LENGTH = len(ARRAY)
if (
ARRAY_LENGTH <= 1
Expand All @@ -37,9 +48,8 @@ def longestSub(ARRAY): # This function is recursive
return TEMPORARY_ARRAY
else:
return LONGEST_SUB



# Some examples

print(longestSub([4, 8, 7, 5, 1, 12, 2, 3, 9]))
print(longestSub([9, 8, 7, 6, 5, 7]))
if __name__ == "__main__":
import doctest
doctest.testmod()