Problem · Array

2020 Account Balance with Monthly Card Fees

Learn this problem
EasyDRW logoDRWFULLTIMEOA

Problem statement

An account records transactions during calendar year 2020. Arrays A and D describe the transactions: A[i] is the signed amount, and D[i] is its date in YYYY-MM-DD format.

Every amount contributes directly to the account balance. A negative amount is a card payment.

The account normally pays a fee of 5 for each of the twelve months. The fee for a month is waived only when that month contains at least three card payments whose combined absolute value is at least 100.

Starting from balance 0, return the final balance after all transactions and all applicable monthly fees.

Function

solution(A: int[], D: String[]) → int

Examples

Example 1

A = [100,-30,-40,-30]D = ["2020-01-01","2020-01-10","2020-01-20","2020-01-30"]return = -55

The transaction amounts sum to 0. January has three card payments totaling 100, so its fee is waived. The other eleven monthly fees total 55.

Example 2

A = [100]D = ["2020-12-01"]return = 40

No month qualifies for a waiver, so twelve fees totaling 60 are subtracted from the transaction total of 100.

Constraints

  • A.length == D.length.
  • Every value in D is a valid date in calendar year 2020 using YYYY-MM-DD format.

More DRW problems

drafts saved locally
public int solution(int[] A, String[] D) {
    // Write your code here.
}
A[100,-30,-40,-30]
D["2020-01-01","2020-01-10","2020-01-20","2020-01-30"]
expected-55
checking account