Detect Pattern of Length M Repeated K or More Times - Problem
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.
Input & Output
Example 1 — Basic Pattern Found
$
Input:
arr = [1,2,4,4,4,4], m = 1, k = 3
›
Output:
true
💡 Note:
Pattern [4] of length 1 repeats 4 times starting at index 2, which is ≥ 3 repetitions required
Example 2 — Pattern Too Short
$
Input:
arr = [1,2,1,2,1,1,1,3], m = 2, k = 2
›
Output:
true
💡 Note:
Pattern [1,2] of length 2 repeats exactly 2 times starting at index 0: [1,2,1,2]
Example 3 — No Pattern Found
$
Input:
arr = [1,2,3,1,2], m = 2, k = 3
›
Output:
false
💡 Note:
No pattern of length 2 repeats 3 or more times. Array length 5 < 2×3=6 required
Constraints
- 2 ≤ arr.length ≤ 100
- 1 ≤ arr[i] ≤ 100
- 1 ≤ m ≤ 100
- 2 ≤ k ≤ 100
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array with potential repeated patterns and parameters m, k
2
Pattern Search
Check each position for patterns of length m repeated k+ times
3
Result
Return true if any valid pattern found
Key Takeaway
🎯 Key Insight: Check each starting position and count consecutive pattern repetitions until the required threshold k is reached
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code