Last active
December 23, 2015 13:59
Find Increasing Triplet Subsequence
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 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