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 prlet if a subsequence which is same as the given subarray is present or not ; Driver code ; Function Call
function checkSubsequenceUtil ( arr , L , R , N ) { for ( let i = 0 ; i < L ; i ++ ) if ( arr [ i ] == arr [ L ] ) return true ; for ( let i = R + 1 ; i < N ; i ++ ) if ( arr [ i ] == arr [ R ] ) return true ; return false ; } function checkSubsequence ( arr , L , R , N ) { if ( checkSubsequenceUtil ( arr , L , R , N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let arr = [ 1 , 7 , 12 , 1 , 7 , 5 , 10 , 11 , 42 ] ; let N = arr . length ; let L = 3 , R = 6 ; checkSubsequence ( arr , L , R , N ) ;