Find a sorted subsequence of size 3 in linear time || Python

 

In this we are going to see a program on how to Find a sorted subsequence of size 3 in linear time in Python Programming Language.


# If there are multiple such triplets, then print any one of them.

def find_sorted_subsequence(a):
    for i in range(len(a) - 2):
        for j in range(i + 1, len(a) - 1):
            for k in range(j + 1, len(a)):
                if a[i] < a[j] < a[k]:
                    return "Elements : ", a[i], a[j], a[k], "Index : " , i, j, k
    return None

print(find_sorted_subsequence([6,8,2,4,7,9,1,3]))

# Coded By DHIRAJ SHELKE

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post