Best week of sales

sliding window

Best week of sales

Target Python Interview Question

Target's store team wants the highest total sales over any run of a fixed number of consecutive days, such as the best 7-day week.

Write a function best_window_total(daily_sales, days) that returns the largest total of any run of exactly that many consecutive days. The list always has at least that many days.

Asked of

  • Data Analyst
  • Data Engineer
  • Data Scientist
  • ML Engineer
  • AI Engineer

Example 1

Input

daily_sales = [2, 1, 5, 4, 4, 4], days = 3

Output

13

Example 2

Input

daily_sales = [7, 3], days = 1

Output

7

Explanation

In the first example, the 3-day runs add up to 8, 11, 13 and 12, so the best is 13, from the days with sales 5, 4 and 4.

Submit also runs 3 hidden test cases that check edge cases.