Leetcode 1716: Calculate Money in Leetcode Bank

grid47
grid47
Exploring patterns and algorithms
May 19, 2024 5 min read

Hercy is saving money for his first car. He deposits money into his Leetcode bank account every day. On the first day (Monday), he deposits $1. For every subsequent day from Tuesday to Sunday, he deposits $1 more than the previous day. Every Monday, he increases his deposit by $1 compared to the previous Monday. Given a number n, representing the number of days Hercy saves money, return the total amount of money he has saved after the nth day.
Problem
Approach
Steps
Complexity
Input: You are given an integer `n`, which represents the number of days Hercy has saved money.
Example: Input: n = 5
Constraints:
• 1 <= n <= 1000
Output: Return the total amount of money Hercy has saved after `n` days.
Example: Output: 15
Constraints:
• The output will be a positive integer.
Goal: To compute the total amount Hercy saves in `n` days.
Steps:
• 1. Initialize the deposit for the first Monday as $1.
• 2. For each day, add the deposit for that day (increasing each week).
• 3. After every 7 days, increase the deposit for the following Monday by $1.
Goal: The input size and values should be handled efficiently within the given constraints.
Steps:
• 1 <= n <= 1000
Assumptions:
• The number of days `n` is always between 1 and 1000.
Input: Input: n = 5
Explanation: Hercy deposits $1 on Monday, $2 on Tuesday, $3 on Wednesday, $4 on Thursday, and $5 on Friday. The total saved is 1 + 2 + 3 + 4 + 5 = 15.

Input: Input: n = 10
Explanation: Hercy deposits: [1, 2, 3, 4, 5, 6, 7] on the first week and [2, 3, 4, 5, 6, 7, 8] on the second week. The total saved is 37.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus