Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Bank Account with Cashback Rule
00:00
5 left

Bank Account with Cashback Rule

MediumPython

Problem

Implement a bank account that supports deposit and withdraw operations. Withdrawals are more complex: 24 hours after a withdrawal, a cashback equal to 2% of the withdrawn amount is credited back, and the bank balance must be tracked/updated accordingly.

Asked in the online assessment stage. This was the only coding question among 12 total OA questions; the rest was non-coding and reported as difficult.

I/O Contract

Implement bank_account(initial_balance, operations). operations contains chronological [timestamp, type, amount] records, where type is "deposit" or "withdraw". Return the balance after each operation. Apply all cashback due at or before an operation's timestamp first. Reject withdrawals exceeding the current balance. Amounts are integer cents, and withdrawal amounts are divisible by 50.

Constraints

  • 0 <= initial_balance <= 10^9
  • 0 <= operations.length <= 1000
  • 0 <= timestamp <= 10^9
  • Operations are sorted by nondecreasing timestamp
  • Each amount is a positive integer number of cents
  • Each withdrawal amount is divisible by 50
  • Operation type is either "deposit" or "withdraw"

Function Signature

def bank_account(initial_balance, operations):
Interviewer

Your question is Bank Account with Cashback Rule. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.