Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
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
Sign up free to run your codeLog inLn 2
Run your code to see test output here.