Created
February 22, 2012 20:24
-
-
Save maxlikely/1887000 to your computer and use it in GitHub Desktop.
Longest Oscillating Sub-sequence Naive
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 los(A,k): | |
"""Auxiliary function for additional parameter k""" | |
if len(A) < 2: return 0 | |
plusOrMinus = lambda x, y: abs(x, y) < 2 | |
# don't take element 0 | |
m = las(A[1:], k) | |
# take element 0 | |
if plusOrMinus(A[0], k): m = max(m, 1 + las(A[1:], A[0])) | |
return m | |
def longest_oscillating_subsequence(A): | |
"""Naive approach to find longest increasing sub-sequence s.t. every | |
element is +/-1 of previous""" | |
if not A: return 0 | |
return los(A,A[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment