Check if any subarray of length M repeats at least K times consecutively or not | C # program for the above approach ; Function to check if any subarray of length M repeats at least K times consecutively or not ; Stores the required count of repeated subarrays ; Check if the next continuous subarray has equal elements ; Check if K continuous subarray of length M are found or not ; If no subarrays are found ; Driver Code
using System ; class GFG { public static bool checkExists ( int [ ] arr , int N , int M , int K ) { int count = 0 ; for ( int i = 0 ; i < N - M ; i ++ ) { if ( arr [ i ] == arr [ i + M ] ) count ++ ; else count = 0 ; if ( count == M * ( K - 1 ) ) return true ; } return false ; } public static void Main ( ) { int [ ] arr = { 2 , 1 , 2 , 1 , 1 , 1 , 3 } ; int N = arr . Length ; int M = 2 , K = 2 ; if ( checkExists ( arr , N , M , K ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }