PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates implementation skills in sequential operation processing, integer arithmetic, control flow, edge-case handling, and overflow awareness within algorithmic constraints.

  • Medium
  • Coinbase
  • Coding & Algorithms
  • Software Engineer

Implement bank account with cashback

Company: Coinbase

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

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 / 100) 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( 1) 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.

Quick Answer: 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. You are given an initial non-negative integer balance `B` and a list of `ops` (n up to 1e5). Apply each operation in order and return the final balance. Each operation is a string of the form `"COMMAND value"`: - `DEPOSIT x` — add `x` to the balance. - `WITHDRAW x` — subtract `x` from the balance only if the current balance is `>= x`; otherwise ignore the operation. - `CASHBACK p` — credit `floor(balance * p / 100)` to the balance (i.e. add `p` percent of the current balance, rounded down). All `x` and `p` are non-negative integers. Use 64-bit integers to avoid overflow. Aim for O(n) time and O(1) extra space. Example: `B = 100`, `ops = ["DEPOSIT 50", "WITHDRAW 120", "CASHBACK 10", "WITHDRAW 15"]` → `18`.

Constraints

  • 0 <= B (initial balance fits in a 64-bit integer)
  • 0 <= n <= 1e5 (number of operations)
  • Each operation is one of DEPOSIT x, WITHDRAW x, CASHBACK p
  • x and p are non-negative integers
  • WITHDRAW x is ignored if balance < x
  • CASHBACK p credits floor(balance * p / 100)
  • Use 64-bit arithmetic to avoid overflow

Examples

Input: (100, ["DEPOSIT 50", "WITHDRAW 120", "CASHBACK 10", "WITHDRAW 15"])

Expected Output: 18

Explanation: 100 +50=150; withdraw 120 (150>=120) ->30; cashback 10% = floor(3)=3 ->33; withdraw 15 (33>=15) ->18.

Input: (0, [])

Expected Output: 0

Explanation: Empty operation list leaves the initial balance of 0 unchanged.

Input: (50, ["WITHDRAW 100"])

Expected Output: 50

Explanation: Balance 50 < 100 so the withdrawal is ignored and the balance stays 50.

Input: (100, ["CASHBACK 0", "DEPOSIT 0", "WITHDRAW 0"])

Expected Output: 100

Explanation: Zero-amount operations are all no-ops: 0% cashback adds 0, depositing 0 adds 0, withdrawing 0 (100>=0) subtracts 0.

Input: (100, ["CASHBACK 50", "CASHBACK 50", "CASHBACK 50"])

Expected Output: 337

Explanation: 100 -> +50=150 -> +75=225 -> +floor(112.5)=112 ->337. Consecutive cashbacks compound off the updated balance with floor rounding.

Input: (1000000000000, ["DEPOSIT 1000000000000", "CASHBACK 100"])

Expected Output: 4000000000000

Explanation: 1e12 + 1e12 = 2e12; 100% cashback adds another 2e12 -> 4e12. Requires 64-bit integers.

Input: (99, ["CASHBACK 99"])

Expected Output: 197

Explanation: floor(99*99/100)=floor(98.01)=98; 99+98=197, exercising floor division on a non-round percentage.

Hints

  1. Process the operations in a single left-to-right pass; you only need one running balance variable, giving O(n) time and O(1) extra space.
  2. Parse each operation by splitting on whitespace into a command and an integer value.
  3. For WITHDRAW, guard with `if balance >= x` so an oversized withdrawal is silently skipped rather than driving the balance negative.
  4. For CASHBACK, compute the credit as integer floor division: `(balance * p) // 100`. Keep everything in 64-bit integers so `balance * p` does not overflow.
Last updated: Jun 25, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement an In-Memory Database - Coinbase (hard)
  • Implement a Coin-Constrained Jump Strategy - Coinbase (hard)
  • Implement Game Physics and Block Mining - Coinbase (hard)
  • Compute Total Manual Distance - Coinbase (medium)
  • Implement a Flappy Bird Jump Agent - Coinbase