Date: 2026-06-06
Time: 15:30
calculate-money-in-leetcode-bank/solution.pySolves LeetCode 1716. The problem models a weekly savings pattern: on day 1 (Monday) of week 1 you deposit $1, incrementing by $1 each day through Sunday ($7). Each subsequent Monday starts $1 higher than the previous Monday. Given n days, return the total deposited.
Solution.totalMoney(n: int) -> int — the single method. It computes the answer in O(1) using closed-form arithmetic rather than simulating day by day.
The method decomposes n into complete weeks and a remainder, then sums each part with arithmetic series formulas:
1. fullweeks = n // 7 and remainingdays = n % 7 — split the timeline.
2. Complete weeks sum — Week k (0-indexed) deposits values (k+1), (k+2), ..., (k+7), totaling 28 + 7k. Summing over all complete weeks:
weekstotal = fullweeks * 28 + 7 * fullweeks * (fullweeks - 1) // 2
This is Σ(28 + 7k) for k = 0..full_weeks-1, which expands to 28W + 7·W(W-1)/2.
3. Remaining days sum — The partial week's Monday starts at deposit value fullweeks + 1. The remaining days deposit (fullweeks+1), (fullweeks+2), ..., (fullweeks+remaining_days):
daystotal = remainingdays * (fullweeks + 1) + remainingdays * (remaining_days - 1) // 2
This is the standard sum of an arithmetic sequence starting at fullweeks + 1 with remainingdays terms.
4. Return weekstotal + daystotal.
// throughout, keeping everything in int — no floating point.calculate-money-in-leetcode-bank/test_solution.py (the "Imported By" list in the prompt is the full test suite across all problems — a shared test harness imports every solution).n >= 1 is assumed (per LeetCode constraints: 1 <= n <= 1000). No guard clause.fullweeks >= 0 and 0 <= remainingdays < 7, which // and % guarantee for non-negative n.None. The method trusts its input matches the LeetCode contract. Passing n = 0 would return 0 (correct by convention). Negative n would produce a nonsensical but non-crashing result due to Python's floor-division semantics.