Check if a non | C # program for the above approach ; 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 print if a subsequence which is same as the given subarray is present or not ; Driver code ; Function Call
using System ; class GFG { static bool checkSubsequenceUtil ( int [ ] arr , int L , int R , int N ) { for ( int i = 0 ; i < L ; i ++ ) if ( arr [ i ] == arr [ L ] ) return true ; for ( int i = R + 1 ; i < N ; i ++ ) if ( arr [ i ] == arr [ R ] ) return true ; return false ; } static void checkSubsequence ( int [ ] arr , int L , int R , int N ) { if ( checkSubsequenceUtil ( arr , L , R , N ) ) { Console . Write ( " YES STRNEWLINE " ) ; } else { Console . Write ( " NO STRNEWLINE " ) ; } } public static void Main ( ) { int [ ] arr = { 1 , 7 , 12 , 1 , 7 , 5 , 10 , 11 , 42 } ; int N = arr . Length ; int L = 3 , R = 6 ; checkSubsequence ( arr , L , R , N ) ; } }