Bank Account Ledger
Programming Interview
Medium
9 views
Problem Description
Simulate one bank account. Start balance = 0. Commands: DEPOSIT x, WITHDRAW x, FEE x. WITHDRAW fails if balance
Input Format
See description.
Output Format
See description.
Sample Test Case
Input:
5
DEPOSIT 100
WITHDRAW 30
WITHDRAW 100
FEE 10
WITHDRAW 20
Constraints
Total operations up to 200000.
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if not lines or not lines[0].strip():
sys.exit(0)
q=int(lines[0].strip())
bal=0
failed=0
for i in range(1,1+q):
parts=(lines[i] if i < len(lines) else '').split()
if len(parts)<2:
continue
cmd=parts[0]
x=int(parts[1])
if cmd=='DEPOSIT':
bal+=x
elif cmd=='WITHDRAW':
if bal<x:
failed+=1
else:
bal-=x
else:
bal-=x
sys.stdout.write(f'{bal} {failed}')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!