Implement bank account with cashback
CoinbaseSoftware Engineer · Technical ScreenLast updated
This question evaluates implementation skills in sequential operation processing, integer arithmetic, control flow, edge-case handling, and overflow awareness within algorithmic constraints.
Implement a bank account processor. Given an initial non-negative integer balance B and a list of operations (n up to 1e 5), apply each operation in order and return the final balance. Operations are: (
- DEPOSIT x — add x to the balance; (
- WITHDRAW x — subtract x only if balance ≥ x, otherwise ignore the operation; (
- CASHBACK p — credit floor(balance * p /
- to the balance. Assume all x and p are non-negative integers; use 64-bit integers to avoid overflow. Target O(n) time and O(
- extra space. Provide unit tests for edge cases (zero amounts, multiple consecutive cashbacks, ignored withdrawals, large values). Example: B=100, ops=["DEPOSIT 50","WITHDRAW 120","CASHBACK 10","WITHDRAW 15"] → 18.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.