LeetCode solutions

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

My accepted Python solution to LeetCode problem 1689, Detect Pattern of Length M Repeated K or More Times, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.4MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.4MB, accepted 2025-12-30.

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

Source