Bird
0
0

Consider this pseudocode for balance calculation:

medium📝 Analysis Q13 of 15
LLD - Design — Splitwise (Expense Sharing)
Consider this pseudocode for balance calculation:
balance = 100
transactions = [20, -10, 30, -5]
for t in transactions:
    balance += t
print(balance)

What will be the printed balance?
A135
B145
C155
D125
Step-by-Step Solution
Solution:
  1. Step 1: Calculate sum of transactions

    Sum = 20 + (-10) + 30 + (-5) = 20 - 10 + 30 - 5 = 35
  2. Step 2: Add sum to initial balance

    Initial balance 100 + 35 = 135
  3. Final Answer:

    135 -> Option A
  4. Quick Check:

    100 + (20 -10 +30 -5) = 135 [OK]
Quick Trick: Add all transactions to initial balance [OK]
Common Mistakes:
  • Adding absolute values instead of signed values
  • Forgetting to add initial balance
  • Miscalculating sum of transactions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes