Reported January 2022
Deloittehash table

Annual Bank Balance with Monthly Card Fees

Reported by candidates from Deloitte's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Deloitte OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this Deloitte OA, reported in January 2022, is charging fees only for months that show up in the data. The problem says all twelve months pay 5, including empty ones. It's a bank balance problem dressed up as a grouping exercise. You bucket transactions by month, count card payments, sum their absolute values, and decide which fees get waived. It's easy code with sneaky edge cases. If you blank during the live assessment, StealthCoder runs invisibly on your desktop and can hand you the solution as a safety net.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The pattern is hash-table grouping, or just two arrays of size 12 indexed by month. Parse the month from the date string with substring(5,7), no date library needed. Add every amount to a running total. For negative amounts, increment that month's payment count and add the absolute value to that month's spend. At the end, start with 12 fees of 5 each, then waive a month only if count >= 3 and spend >= 100. The pitfalls: forgetting empty months, counting positive amounts as payments, summing signed values instead of absolute values, and using strict inequalities where the rule says at least. Zero-length input must return -60. One pass, O(n) time, O(1) space. If the live OA rattles you, StealthCoder is the hedge that keeps a silly off-by-one from costing you the round.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Annual Bank Balance with Monthly Card Fees cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Deloitte's OA.

Deloitte reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Annual Bank Balance with Monthly Card Fees FAQ

How hard is the Annual Bank Balance problem really?+

Easy on algorithm, medium on care. It's a single pass with 12 buckets. The failures come from misreading rules: fees apply to empty months, only negative amounts count as card payments, and the waiver needs both conditions. Read the examples twice before coding.

What's the trick to solving it fast?+

Use two arrays of length 12, one for card payment counts and one for absolute spend. Extract the month with substring(5,7) minus 1. Add every amount to the total. After the loop, subtract 5 per month unless count is at least 3 and spend is at least 100.

What edge cases should I test?+

Empty input should return -60. Test a month with exactly 3 payments totaling exactly 100, which should be waived. Test 3 payments totaling 99, which shouldn't. Also test 2 large payments, and months with only positive amounts, which never qualify for a waiver.

Do I need to parse dates with a date library?+

No. The format is fixed YYYY-MM-DD and all dates are valid and in the same year. Take characters at index 5 and 6, convert to an integer, and subtract 1 for an array index. It's faster and avoids library quirks.

How do I prepare for this in 48 hours?+

Practice bucket-by-key problems: group items by a derived key, aggregate, then apply a rule per group. Write this one from scratch twice, with all three examples as tests. Focus on reading constraints carefully, because the logic itself is short and the mistakes are in the rules.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Deloitte.

OA at Deloitte?
Invisible during screen share
Get it