Magicsheet logo

Calculate Money in Leetcode Bank

Easy
25%
Updated 8/1/2025

Calculate Money in Leetcode Bank

What is this problem about?

The Calculate Money in Leetcode Bank interview question is a mathematical sequence problem. A person puts money into a bank every day. On the first Monday, they put in 1.Everysubsequentday(TuesdaySunday),theyputin1. Every subsequent day (Tuesday-Sunday), they put in 1 more than the day before. On every subsequent Monday, they put in $1 more than the previous Monday. You need to calculate the total amount of money in the bank after n days. This Calculate Money in Leetcode Bank coding problem can be solved either by simulation or by a mathematical formula.

Why is this asked in interviews?

Companies like Microsoft and Amazon use this to see if a candidate can optimize a repeating pattern. It tests your ability to handle arithmetic progressions. While simulation (O(N)) is easy to write, the O(1) mathematical solution shows a deeper understanding of sequences and series.

Algorithmic pattern used

This follows the Math interview pattern. The total money can be broken down into:

  1. The number of full weeks (w = n / 7).
  2. The remaining days (d = n % 7). The sum for each week is an arithmetic progression, and the starting values of each week also form an arithmetic progression.

Example explanation

If n = 10:

  • Week 1: 1, 2, 3, 4, 5, 6, 7 (Total 28)
  • Week 2: Monday starts at 2.
  • Day 8 (Mon): 2
  • Day 9 (Tue): 3
  • Day 10 (Wed): 4 Total = 28 + 2 + 3 + 4 = 37.

Common mistakes candidates make

  • Incorrect Monday logic: Resetting the Monday value to 1 instead of incrementing it from the previous Monday.
  • Off-by-one errors: Miscalculating the start value for the "remaining days" after full weeks are completed.
  • Hardcoding values: Not accounting for the fact that the "base" sum of a week (1+2+3+4+5+6+7 = 28) increases by 7 for every subsequent week.

Interview preparation tip

Practice the formula for the sum of an arithmetic progression: S = n/2 * (2a + (n-1)d). Many sequence-based interview questions can be reduced to this formula, allowing you to provide a more optimal O(1) solution.

Similar Questions