Katkat

Implement bank account with cashback

CoinbaseSoftware Engineer · Technical Screen

Last 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: (

  1. DEPOSIT x — add x to the balance; (
  2. WITHDRAW x — subtract x only if balance ≥ x, otherwise ignore the operation; (
  3. CASHBACK p — credit floor(balance * p /
  4. 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(
  5. 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.