Skip to main content
100%

Find the largest of a sub-array for a specific window size

✓ Published0🌍 Public
PP7h
Last edited Apr 24, 2015
Created on Apr 24, 2015

This example demonstrates the sliding window maximum problem, showing how to find the largest value within every contiguous sub-array of a fixed size as the window moves across an integer array. The Groovy script initializes an array of nine integers and a window size of three, then iterates through the array, extracting each window into a temporary array. For each window, it calls the `getMax` function, which concatenates the window’s elements into a string and identifies the largest value by comparing each element against a running maximum. The output prints each window’s contents followed by an arrow and the computed maximum, illustrating the algorithm’s step-by-step progression without using any visualization libraries.

AI-generated description

Similar vizzes