Given an array of positive integers arr, find a pattern of length m that is repeated k or more times.

A pattern is a subarray (consecutive sub-sequence) that consists of one or more values, repeated multiple times consecutively without overlapping. A pattern is defined by its length and the number of repetitions.

Return true if there exists a pattern of length m that is repeated k or more times, otherwise return false.

&nbsp;
Example 1:

Input: arr = [1,2,4,4,4,4], m = 1, k = 3
Output: true
Explanation: The pattern (4) of length 1 is repeated 4 consecutive times. Notice that pattern can be repeated k or more times but not less.


Example 2:

Input: arr = [1,2,1,2,1,1,1,3], m = 2, k = 2
Output: true
Explanation: The pattern (1,2) of length 2 is repeated 2 consecutive times. Another valid pattern (2,1) is also repeated 2 times.


Example 3:

Input: arr = [1,2,1,2,1,3], m = 2, k = 3
Output: false
Explanation: The pattern (1,2) is of length 2 but is repeated only 2 times. There is no pattern of length 2 that is repeated 3 or more times.


&nbsp;
Constraints:


	2 &lt;= arr.length &lt;= 100
	1 &lt;= arr[i] &lt;= 100
	1 &lt;= m &lt;= 100
	2 &lt;= k &lt;= 100


class Solution:
    def containsPattern(self, arr: List[int], m: int, k: int) -> bool:
        if len(arr) < k*m:
            return False
        
        n = len(arr)
        pattern = arr[0:m]
        repeats = 1
        for i in range(m, n - m + 1, m):
            if arr[i:i+m] != pattern:
                break
            
            repeats += 1
            if repeats >= k:
                return True
            
        return self.containsPattern(arr[1:], m, k)
// Time complexity: O(N)
// Space complexity: O(1)
class Solution {
    public boolean containsPattern(int[] arr, int m, int k) {
        int count = 0;
        for (int i = 0; i < arr.length - m; i++) {
            if (arr[i] == arr[i + m]) {
                count++;
            } else {
                count = 0;
            }
            if (count == m * (k-1)) {
                return true;
            }
        }
        return false;
    }
}
class Solution {
public:
    bool containsPattern(vector<int>& arr, int m, int k) {
        unordered_map<string, vector<int>> ump;
        string num = "";
        for(int i = 0; i < arr.size(); ++i)
            num += to_string(arr[i]);
        for(int i = 0; i <= num.length() - m; ++i){
            string str = num.substr(i, m);
            ump[str].push_back(i);
        }
        for(auto it = ump.begin(); it != ump.end(); ++it){
            if(it->second.size() >= k){
                bool flag = true;
                for(int i = 1; i < it->second.size(); ++i){
                    if(it->second[i] - it->second[i - 1] < m)
                        flag = false;
                }
                if(flag == true)
                    return true;
            }
        }
        return false;
    }
};
var containsPattern = function(arr, m, k) {
	const origin = arr.join(',');

	return arr.some((_, index, array) => {
		const check = arr.slice(index, m + index).join(',') + ',';

		index + k * m > arr.length && array.splice(index);
		const target = check.repeat(k).slice(0, -1);
		if (~origin.indexOf(target)) return true
	});
};
Detect Pattern of Length M Repeated K or More Times