Calculate Money in Leetcode Bank

Hercy saves money every day. On the first Monday he deposits $1, and each following day he deposits $1 more than the day before. Every new Monday he deposits $1 more than the previous Monday. Return the total amount in the bank at the end of day n.

30:00

Calculate Money in Leetcode Bank
easy
Free written solution
Topics
Companies

Hercy saves money every day. On the first Monday he deposits 1,andeachfollowingdayhedeposits1, and each following day he deposits 1 more than the day before. Every new Monday he deposits $1 more than the previous Monday. Return the total amount in the bank at the end of day n.

Example 1:
Input: {"n":4}
Output: 10
Constraints:
  • 1≤n≤10001 \leq n \leq 1000

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"n":4}

4 days = 0 full weeks + 4 leftover days. Each row of the calendar is one week, starting on Monday.

deposits by week · 4 days = 0 × 7 + 4

Mon
Tue
Wed
Thu
Fri
Sat
Sun
week
1
2
3
4
#1

running total

full weeks: 28·0 + 7·0·0/2 → 0
leftover: 4·1 + 4·3/2 → 0

Week k (from 1) deposits k, k+1, ..., k+6, so each full row sums to 7k + 21.

Variables
VariableValue
n4
weeks0
days4
DepthFunction Call
Stack empty
0/6