Created
August 14, 2019 17:57
-
-
Save dionyziz/38c4759ecd54d5c8525aed671f109268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def longest_increasing_subsequence(sequence): | |
best_length = -1 | |
for bitmask in range(2**len(sequence)): | |
subsequence = [] | |
for bit_idx in range(len(sequence)): | |
if bitmask & (1 << bit_idx): | |
subsequence.append(sequence[bit_idx]) | |
if not sorted(subsequence) == subsequence: | |
continue | |
if len(subsequence) > best_length: | |
best_length = len(subsequence) | |
best = subsequence | |
return best | |
print(longest_increasing_subsequence([1, 5, 2, 3, 9, 10, 3, 3, 5])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment