1566. Detect Pattern of Length M Repeated K or More Times

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1566

class Solution:
    def containsPattern(self, arr: List[int], m: int, k: int) -> bool:
        n = len(arr)
        for i in range(n - m * k + 1):
            j = 0
            while j < m * k:
                if arr[i + j] != arr[i + (j % m)]:
                    break
                j += 1
            if j == m * k:
                return True
        return False