Sliding Window Algorithm Approach(Go example)

Photo by Sebastian Staines on Unsplash

Why use the Sliding Window?

What is the sliding window?

Given an array of integers and a number, write a function which finds the maximum sum of a subarray with the length of the number passed to the function. Ifex:
maxSubarraySum([]int{1, 1, 2, 4, 2, 3, 5, 1}, 4) //14
maxSubarraySum([]int{100, 200, 300, 400}, 2) //700
maxSubarraySum([]int{}, 2) //0

When should I use the Sliding Window?