Level: Senior-Level
Round: Online Assessment · Type: Coding · Difficulty: 6/10 · Duration: 60 min · Interviewer: Neutral
Topics: Object-Oriented Programming, Data Structures, Algorithms
Location: San Francisco Bay Area
Interview date: 2026-01-20
Question: Design a simple banking system with account creation, deposits, and transfers, including timestamping.
Design a basic banking service that allows users to open accounts, deposit funds, and move money between accounts. Each request includes an integer timestamp, and all requests arrive in strictly increasing order of time, representing events in a real-time system.
Implement the BankingSystem class with the following methods:
BankingSystem()
Initializes the system with no accounts.
boolean createAccount(int timestamp, String accountId)
Creates a new account with the identifier accountId. The account should start with a balance of 0.
true if the account is successfully created.false if an account with the same accountId already exists.int deposit(int timestamp, String accountId, int amount)
Adds the specified amount to the balance of the account identified by accountId.
-1.int transfer(int timestamp, String sourceAccountId, String targetAccountId, int amount)
Moves amount of money from sourceAccountId to targetAccountId.
If the transfer completes successfully, return the new balance of the source account.
Return -1 if any of the following conditions occur:
Solution ` from typing import List, Optional
class BankingSystem: def init(self, ): self.accounts = {} # Map to store account balances
def createAccount(self, timestamp: int, accountId: str) -> bool:
if accountId in self.accounts:
return False
self.accounts[accountId] = 0
return True
def deposit(self, timestamp: int, accountId: str, amount: int) -> int:
if accountId not in self.accounts:
return -1
newBalance = self.accounts[accountId] + amount
self.accounts[accountId] = newBalance
return newBalance
def transfer(self, timestamp: int, sourceAccountId: str, targetAccountId: str, amount: int) -> int:
# Check if both accounts exist and are not the same
if (sourceAccountId not in self.accounts or targetAccountId not in self.accounts
or sourceAccountId == targetAccountId):
return -1
# Check if the source account has enough balance
sourceBalance = self.accounts[sourceAccountId]
if sourceBalance < amount:
return -1
self.accounts[sourceAccountId] = sourceBalance - amount
self.accounts[targetAccountId] = self.accounts[targetAccountId] + amount
return self.accounts[sourceAccountId]
`