Problem 170466 · easy · Phase 01 Prerequisites & Setup

Bank Balance History

loops · conditionals · lists

Simulate a bank account that starts at 0. transactions is a list of [kind, amount] pairs where kind is "deposit" or "withdraw". A withdrawal larger than the current balance is rejected and leaves the balance unchanged. Return the list of balances after every transaction, rejected ones included.

Examples

Input:  transactions = [["deposit", 50], ["withdraw", 80], ["withdraw", 30], ["deposit", 5]]
Output: [50, 50, 20, 25]

Input:  transactions = [["withdraw", 10]]
Output: [0]

Constraints

  • 0 <= len(transactions) <= 1000, 0 <= amount <= 10**6

Goals

  • Keep a running balance while processing events in order
  • Reject an event without stopping the simulation
Starting Python…