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
ExperiencesCoaching
New
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
Get started
In-Memory Banking Operations
00:00
5 left

In-Memory Banking Operations

HardPython

Problem

Implement a transaction processor for Capital One accounts. The processor must support deposits, withdrawals, transfers, and queries for the most active accounts.

An account is identified by a unique string and has a nonnegative integer balance. An account's activity score is the total value of all successful withdrawals and outgoing transfers from that account. Deposits and incoming transfers do not increase the score.

Formal Specification

Implement account_operations(accounts, operations), where accounts is a dictionary mapping account IDs to initial balances, and operations is a list of operation arrays:

  1. ["deposit", account_id, amount]
  2. ["withdraw", account_id, amount]
  3. ["transfer", source_id, destination_id, amount]
  4. ["top", n]

Return one result for every operation that changes state or queries state. Deposit, withdrawal, and transfer return true on success and false otherwise. A transaction fails if an account is unknown, an amount is not positive, or the source balance is insufficient. A transfer must be atomic. A top query returns up to n account IDs sorted by descending activity score, then lexicographically by account ID.

Constraints

  • 1 <= len(accounts) <= 10^5
  • 1 <= len(operations) <= 10^5
  • Initial balances and amounts are integers from 0 through 10^9
  • 1 <= n <= len(accounts)
  • Account IDs are unique strings containing lowercase letters and digits
  • Only accounts present in the initial accounts dictionary may transact

Function Signature

def account_operations(accounts, operations):
Interviewer

Your question is In-Memory Banking Operations. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.