Check if a non | Utility Function to check whether a subsequence same as the given subarray exists or not ; Check if first element of the subarray is also present before ; Check if last element of the subarray is also present later ; If above two conditions are not satisfied , then no such subsequence exists ; Function to check and prif a subsequence which is same as the given subarray is present or not ; Driver Code ; Function Call
def checkSubsequenceUtil ( arr , L , R , N ) : NEW_LINE INDENT for i in range ( L ) : NEW_LINE INDENT if ( arr [ i ] == arr [ L ] ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT for i in range ( R + 1 , N , 1 ) : NEW_LINE INDENT if ( arr [ i ] == arr [ R ] ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def checkSubsequence ( arr , L , R , N ) : NEW_LINE INDENT if ( checkSubsequenceUtil ( arr , L , R , N ) ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT arr = [ 1 , 7 , 12 , 1 , 7 , 5 , 10 , 11 , 42 ] NEW_LINE N = len ( arr ) NEW_LINE L = 3 NEW_LINE R = 6 NEW_LINE checkSubsequence ( arr , L , R , N ) NEW_LINE