On February 24, 2025, communities are preparing for a festive celebration. Local vendors want to determine the best sequence of consecutive days to showcase their best sales leading into the festival. Given an array of integers where each element represents the sales for a day and an integer k representing a fixed number of consecutive days, find the maximum total sales that can be achieved in any contiguous subarray of size k.
sales
representing daily sales.k
specifying the window size.k
.Input: sales = [1, 3, 2, 5, 7, 2, 4], k = 3
Output: 14
Explanation: The subarray [5, 7, 2] has a sum of 14 which is the maximum possible sum for any subarray of length 3.
Happy coding and enjoy the festive spirit!