Library Late Fee Calculator
You are given an integer array daysLate, where daysLate[i] represents the number of days the ith book was returned after its due date.
The library charges a penalty based on the following rules:
- If a book is returned exactly 1 day late, the penalty is 1.
- If a book is returned between 2 and 5 days late (inclusive), the penalty is 2 × daysLate[i].
- If a book is returned more than 5 days late, the penalty is 3 × daysLate[i].
Your task is to return the total penalty collected from all books.
Example 1:
Input: daysLate = [2, 4, 6]
Output: 30
Explanation:
- 2 days late → 2 × 2 = 4
- 4 days late → 2 × 4 = 8
- 6 days late → 3 × 6 = 18
Total penalty = 4 + 8 + 18 = 30
Example 2:
Input: daysLate = [1, 3, 5]
Output: 17
Explanation:
- 1 day late → 1
- 3 days late → 2 × 3 = 6
- 5 days late → 2 × 5 = 10
Total penalty = 1 + 6 + 10 = 17
Now Your Turn!
Pick the correct output for the given inputInput: daysLate = [1, 2, 6]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 ≤ daysLate.length ≤ 104
- 1 ≤ daysLate[i] ≤ 104
- Each element represents the delay of one returned book.
- The array contains only positive integers.