Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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
Simulate a Bank Application
00:00
5 left

Simulate a Bank Application

HardPython

Problem

Build a software application simulating a bank.

Implement simulate_bank(operations), which processes operations in order while maintaining account balances. Support account creation, deposits, withdrawals, transfers, and balance queries. Deposits, withdrawals, and transfers include unique transaction IDs and must be idempotent: repeating an ID returns the original result without changing state. Transfers must be atomic, so insufficient funds or invalid accounts leave both balances unchanged.

Contract

Input is a list of operation dictionaries. Return one result dictionary per operation. Amounts are nonnegative integer cents. Use {"ok": true} for successful mutations, include balance for balance queries and successful deposits or withdrawals, and use {"ok": false, "error": "..."} for rejected operations. Use the exact operation shapes shown in the examples.

Constraints

  • 1 <= operations.length <= 200000
  • Account identifiers are nonempty strings
  • Amounts and initial balances are integers in the range 0 through 10^12
  • Every DEPOSIT, WITHDRAW, and TRANSFER operation contains a unique transaction ID unless it is an intentional retry
  • Transaction IDs are strings
  • Operations are processed strictly in input order

Function Signature

def simulate_bank(operations):
Interviewer

Your question is Simulate a Bank Application. 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.