Trains the technique from
LeetCode 1191K-Concatenation Maximum SumThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A conveyor test rig runs the same programme during every shift. The programme is given as pattern, a list of the net balance changes it records in each of its slots, and the rig runs repeats identical shifts back to back. The full log is therefore pattern written out repeats times in order, so the log holds pattern.length * repeats entries.
A window is a contiguous run of entries of the full log, and its value is the sum of the entries it covers. The empty window is allowed and its value is 0.
Return the largest window value in the full log, taken modulo 1000000007. Compare windows by their exact sums and reduce only the number you return.
Example 1
The full log is 4, -3, 6, 4, -3, 6, 4, -3, 6. The window that covers all nine entries has value 21, and 21 modulo 1000000007 is 21.
Example 2
Every entry of the log is negative. The empty window is allowed and its value is 0, so 0 is reported.
Example 3
The full log is 5, -11, 5, 5, -11, 5, 5, -11, 5. The window covering the third and fourth entries has value 10.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def best_repeated_window(pattern: list[int], repeats: int) -> int:public int bestRepeatedWindow(int[] pattern, int repeats)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.