Calculate Money in Leetcode Bank - Problem

Hercy wants to save money for his first car. He puts money in the Leetcode bank every day.

He starts by putting in $1 on Monday, the first day. Every day from Tuesday to Sunday, he will put in $1 more than the day before. On every subsequent Monday, he will put in $1 more than the previous Monday.

Given n, return the total amount of money he will have in the Leetcode bank at the end of the nth day.

Input & Output

Example 1 — Basic Case
$ Input: n = 4
Output: 10
💡 Note: Day 1 (Mon): $1, Day 2 (Tue): $2, Day 3 (Wed): $3, Day 4 (Thu): $4. Total: 1+2+3+4 = 10
Example 2 — Complete Week
$ Input: n = 10
Output: 37
💡 Note: Week 1: $1+$2+$3+$4+$5+$6+$7 = $28. Week 2 (3 days): $2+$3+$4 = $9. Total: 28+9 = 37
Example 3 — Single Day
$ Input: n = 1
Output: 1
💡 Note: Only Monday of first week: $1

Constraints

  • 1 ≤ n ≤ 1000

Visualization

Tap to expand
Leetcode Bank Savings PatternInput: n = 10 days$1$2$3$4$5$6$7MonTueWedThuFriSatSunWeek 1: $28$2$3$4MonTueWedWeek 2 (3 days): $9Total Output: $28 + $9 = $37
Understanding the Visualization
1
Input
Number of days n
2
Pattern
Weekly deposits: Mon+1, Tue+1, ..., Sun+1, then next Monday+1
3
Output
Total money saved after n days
Key Takeaway
🎯 Key Insight: Each week follows the same pattern but with Monday amount incrementing by $1
Asked in
Google 15 Amazon 12
28.0K Views
Medium Frequency
~15 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen