Check if any subarray of length M repeats at least K times consecutively or not | 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
def checkExists ( arr , N , M , K ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( N - M ) : NEW_LINE INDENT if ( arr [ i ] == arr [ i + M ] ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT count = 0 NEW_LINE DEDENT if ( count == M * ( K - 1 ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 1 , 2 , 1 , 1 , 1 , 3 ] NEW_LINE N = len ( arr ) NEW_LINE M = 2 NEW_LINE K = 2 NEW_LINE if ( checkExists ( arr , N , M , K ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT