int scanFixedWindow(int[] values, int width) {
int window = 0;
for (int i = 0; i < width; i++) window += values[i];
int best = score(window);
for (int right = width; right < values.length; right++) {
window += values[right] - values[right - width];
best = combine(best, score(window));
}
return best;
}
def scan_fixed_window(values: list[int], width: int) -> int:
window = sum(values[:width])
best = score(window)
for right in range(width, len(values)):
window += values[right] - values[right - width]
best = combine(best, score(window))
return best
def scanFixedWindow(values: Array[Int], width: Int): Int =
var window = values.take(width).sum
var best = score(window)
for right <- width until values.length do
window += values(right) - values(right - width)
best = combine(best, score(window))
best
int scanFixedWindow(const std::vector<int>& values, int width) {
int window = 0;
for (int i = 0; i < width; i++) window += values[i];
int best = score(window);
for (int right = width; right < values.size(); right++) {
window += values[right] - values[right - width];
best = combine(best, score(window));
}
return best;
}