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

@problem@discussion
#Array#Enumeration



1/**
2 * [1566] Detect Pattern of Length M Repeated K or More Times
3 *
4 * Given an array of positive integers arr, find a pattern of length m that is repeated k or more times.
5 * 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.
6 * Return true if there exists a pattern of length m that is repeated k or more times, otherwise return false.
7 *  
8 * Example 1:
9 * 
10 * Input: arr = [1,2,4,4,4,4], m = 1, k = 3
11 * Output: true
12 * 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.
13 * 
14 * Example 2:
15 * 
16 * Input: arr = [1,2,1,2,1,1,1,3], m = 2, k = 2
17 * Output: true
18 * Explanation: The pattern (1,2) of length 2 is repeated 2 consecutive times. Another valid pattern (2,1) is also repeated 2 times.
19 * 
20 * Example 3:
21 * 
22 * Input: arr = [1,2,1,2,1,3], m = 2, k = 3
23 * Output: false
24 * 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.
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	2 <= arr.length <= 100
30 * 	1 <= arr[i] <= 100
31 * 	1 <= m <= 100
32 * 	2 <= k <= 100
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times/
38// discuss: https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn contains_pattern(arr: Vec<i32>, m: i32, k: i32) -> bool {
44        false
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_1566() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.