Skip to content
← Back to the archive

23 August 2026

Weekly Spend

Hard Dictionaries

Add purchases for each day, then find the day with the largest total.

You are given a list called purchases. Each purchase contains a day name and a whole-number amount. For example, ("Monday", 12) means that 12 was spent on Monday. First, add together all the amounts for each day. Then compare those daily totals and return the day with the largest total. If two or more days have the same largest total, return the day whose first purchase appears earlier in the list. If purchases is empty, return None. For example, [("Monday", 12), ("Tuesday", 7), ("Monday", 5)] returns "Monday" because Monday's total is 17.

Constraints

  • 0 <= len(purchases) <= 10000
  • Each purchase is a (day, amount) pair.
  • day is a non-empty string and amount is a non-negative whole number.

Function signature

def weekly_spend(purchases):

Sign in to solve this bracket

Reading the problem is free for everyone. Opening the editor and solving it requires an account with Open Bracket+.