PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates object-oriented programming, state management, input validation, and arithmetic correctness when implementing account operations and maintaining transactional invariants.

  • Medium
  • Coinbase
  • Coding & Algorithms
  • Software Engineer

Implement bank balance operations

Company: Coinbase

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

##### Question Design and implement a Bank account class that supports the operations Deposit(amount), Withdraw(amount), and CashBack(percent). Ensure balance updates correctly, prevent overdrafts, and return the updated balance after each operation.

Quick Answer: This question evaluates object-oriented programming, state management, input validation, and arithmetic correctness when implementing account operations and maintaining transactional invariants.

Design a bank account that processes a sequence of operations and returns the resulting balance after each one. You are given a list of operations. Each operation is a pair `[opType, value]` where `opType` is: - `0` = Deposit `value` dollars into the account. - `1` = Withdraw `value` dollars from the account. - `2` = CashBack: add `value` percent of the current balance back to the account (integer cashback, floor division). The account starts with a balance of `0`. Apply the operations in order and, for each one, append the resulting balance to an output list. Validation rules (an operation that violates a rule is REJECTED — the balance is left unchanged and you append `-1` for that operation): - Deposit: `value` must be positive (`> 0`). - Withdraw: `value` must be positive and must not exceed the current balance (no overdrafts). - CashBack: `value` (the percent) must be non-negative (`>= 0`). Return the list of results, one entry per operation. Example: operations `[[0,100],[1,30],[2,10]]` -> deposit 100 (balance 100), withdraw 30 (balance 70), cashback 10% of 70 = 7 (balance 77) -> returns `[100, 70, 77]`.

Constraints

  • 0 <= operations.length <= 10^4
  • Each operation is a pair [opType, value] with opType in {0, 1, 2}
  • 0 <= value <= 10^6
  • Account starts at balance 0
  • A rejected operation (invalid amount or overdraft) leaves the balance unchanged and yields -1
  • CashBack uses integer floor division: added amount = balance * percent // 100

Examples

Input: ([[0, 100], [1, 30], [2, 10]],)

Expected Output: [100, 70, 77]

Explanation: Deposit 100 -> 100; withdraw 30 -> 70; cashback 10% of 70 = 7 -> 77.

Input: ([[0, 50], [1, 80]],)

Expected Output: [50, -1]

Explanation: Deposit 50 -> 50; withdraw 80 exceeds balance, rejected -> -1 (balance stays 50).

Input: ([[1, 10]],)

Expected Output: [-1]

Explanation: Withdraw 10 on an empty account is rejected -> -1.

Input: ([],)

Expected Output: []

Explanation: No operations -> empty result list.

Input: ([[0, 200], [2, 5], [1, 210], [1, 5]],)

Expected Output: [200, 210, 0, -1]

Explanation: Deposit 200 -> 200; cashback 5% = 10 -> 210; withdraw 210 (= balance) -> 0; withdraw 5 exceeds balance 0, rejected -> -1.

Input: ([[0, -5], [0, 100], [2, -1]],)

Expected Output: [-1, 100, -1]

Explanation: Deposit -5 invalid -> -1; deposit 100 -> 100; cashback with negative percent invalid -> -1.

Hints

  1. Maintain a single running balance and append the new balance after each accepted operation.
  2. Withdraw must be rejected (append -1, leave balance unchanged) whenever the requested amount exceeds the current balance — this is how you prevent overdrafts.
  3. For cashback, compute balance * percent // 100 using integer (floor) division and add it to the balance.
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 a Coin-Constrained Jump Strategy - Coinbase (hard)
  • Implement an In-Memory Database - Coinbase (hard)
  • Implement Game Physics and Block Mining - Coinbase (hard)
  • Compute Total Manual Distance - Coinbase (medium)
  • Implement a Flappy Bird Jump Agent - Coinbase