Check if an array can be split into K consecutive non | Function to check if array can be split into K consecutive and non - overlapping subarrays of length M consisting of a single distinct element ; Traverse over the range [ 0 , N - M - 1 ] ; Check if arr [ i ] is the same as arr [ i + m ] ; Increment current length t of pattern matched by 1 ; Check if t is equal to m , increment count of total repeated pattern ; Return true if length of total repeated pattern is k ; Update length of the current pattern ; Update count to 1 ; Finally return false if no pattern found ; Driver Code
def checkPattern ( arr , m , k , n ) : NEW_LINE INDENT count = 1 NEW_LINE t = 0 NEW_LINE for i in range ( n - m ) : NEW_LINE INDENT if ( arr [ i ] == arr [ i + m ] ) : NEW_LINE INDENT t += 1 NEW_LINE if ( t == m ) : NEW_LINE INDENT t = 0 NEW_LINE count += 1 NEW_LINE if ( count == k ) : NEW_LINE INDENT return " Yes " NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT t = 0 NEW_LINE count = 1 NEW_LINE DEDENT DEDENT return " No " NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 6 , 1 , 3 , 3 , 3 , 3 ] NEW_LINE M = 1 NEW_LINE K = 3 NEW_LINE N = len ( arr ) NEW_LINE print ( checkPattern ( arr , M , K , N ) ) NEW_LINE DEDENT