Ctrl K

Repeated Block Run

Easy
You are given an array of positive integers values and two integers width and times. Check whether the array contains a block of width consecutive elements that is immediately followed, with no gaps and no overlap, by at least times - 1 more copies of the same block. In other words, is there a stretch of length width * times made of a single block of length width written times times in a row? The block may repeat more than times times. Return True if such a block exists and False otherwise.
Example 1
values=[7, 3, 8, 3, 8, 3, 8, 1], width=2, times=3 → True

The block [3, 8] appears three times in a row starting at index 1.

Example 2
values=[5, 5, 2, 5, 5], width=2, times=2 → False

[5, 5] occurs twice, but the 2 between them breaks the run. No other block of length 2 works either.

Example 3
values=[6, 6, 6, 6], width=1, times=4 → True

The block [6] repeats exactly four times.

Constraints
  • 2 ≤ len(values) ≤ 100
  • 1 ≤ values[i] ≤ 100
  • 1 ≤ width ≤ 100
  • 2 ≤ times ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsConsistent Reading Triples EasyXOR of Every Subset EasyThree Addends and a Later Total EasyEven Numbers From Digit Cards EasyEvenly Spaced Triples Easy
loading Python…
Input
values=[7, 3, 8, 3, 8, 3, 8, 1], width=2, times=3
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 128 tests on the server, hidden ones included.