FastPrepAnnual Bank Balance with Monthly Card Fees

Annual Bank Balance with Monthly Card Fees

Deloitte logoDeloitte● EasyFULLTIMEOA
Learn

Problem statement

You are given two parallel arrays that describe every transaction made by one bank account during a calendar year:

  • transactions[i] is the signed amount of transaction i. A positive amount is money received, while a negative amount is a card payment.
  • dates[i] is the transaction date in YYYY-MM-DD format. All dates belong to the same calendar year.

Every transaction amount contributes directly to the balance. The account normally pays a fee of 5 for each of the twelve months, including a month with no transactions.

A month's fee is waived only when that month contains at least three card payments and the sum of their absolute values is at least 100.

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

Function

annualAccountBalance(transactions: int[], dates: String[]) → int

Examples

Example 1

transactions = [100,-30,-40,-30]dates = ["2022-01-01","2022-01-10","2022-01-20","2022-01-30"]return = -55

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

Example 2

transactions = [100]dates = ["2022-12-01"]return = 40

No month qualifies for a waiver, so all twelve fees total 60. Subtracting them from the transaction total of 100 gives 40.

Example 3

transactions = [-25,-25,-50,120]dates = ["2022-02-01","2022-02-02","2022-02-03","2022-07-01"]return = -35

The transactions sum to 20. February qualifies for a waiver, while the other eleven months contribute 55 in fees, so the final balance is 20 - 55 = -35.

Constraints

  • transactions.length == dates.length.
  • 0 <= transactions.length <= 100,000.
  • -1,000,000 <= transactions[i] <= 1,000,000.
  • Every value in dates is a valid date in one calendar year using YYYY-MM-DD format.

More Deloitte problems

See Deloitte hiring insights
public int annualAccountBalance(int[] transactions, String[] dates) {
    // Write your code here.
}
transactions[100,-30,-40,-30]
dates["2022-01-01","2022-01-10","2022-01-20","2022-01-30"]
expected-55
Checking account…