Skip to content

Instantly share code, notes, and snippets.

@st0le
Last active December 23, 2015 13:59
Find Increasing Triplet Subsequence
def find_triple(arr): #O(n)/O(1)
mn = a = arr[0]
b = None
for v in arr[1:]:
if mn >= v: # v is the new minimum
mn = v
elif b == None or b > v: # v > min but less than earlier 'b'
a,b = mn,v
else: # v > b > a
return a,b,v
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment