Detect Pattern of Length M Repeated K or More Times

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, or consecutive subsequence, 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.

Example 1
Inputarr = [1,2,4,4,4,4], m = 1, k = 3
Outputtrue
The pattern (4) of length 1 is repeated 4 consecutive times, which is at least k times.
Example 2
Inputarr = [1,2,1,2,1,1,1,3], m = 2, k = 2
Outputtrue
The pattern (1,2) of length 2 is repeated 2 consecutive times, and (2,1) is also repeated 2 times.

Constraints

  • 2 <= arr.length <= 100
  • 1 <= arr[i] <= 100
  • 1 <= m <= 100
  • 2 <= k <= 100

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate