The Busiest Stretch

Data with PythonMedium+10 XP+10

The Busiest Stretch

A market stall wants to plan its staff holidays. It needs to know which run of days in a row was the busiest.

Task: write best_stretch(days, sales, length).

  • days is a list of day names, oldest first, all different. sales is a list of whole numbers, one per day.
  • length is how many days in a row make one stretch. It is at least 1 and never more than the number of days.
  • A stretch's size is the total of its sales.
  • Return the name of the day the busiest stretch starts on.
  • If two stretches tie, return the one that starts earliest.

Examples

days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
sales = [120, 95, 180, 110, 60, 210, 130]
length = 3
returns 'Fri'
days = ['d1', 'd2', 'd3', 'd4', 'd5']
sales = [5, 1, 1, 1, 6]
length = 2
returns 'd4'

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run