0
0
LLDsystem_design~10 mins

Balance calculation algorithm in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the balance variable correctly.

LLD
balance = [1]
Drag options to blanks, or click blank then click option'
A0
BNone
C''
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing balance as None causes errors when adding amounts.
Using a negative number as initial balance is incorrect.
2fill in blank
medium

Complete the code to add a transaction amount to the balance.

LLD
balance = balance [1] transaction_amount
Drag options to blanks, or click blank then click option'
A/
B+
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition reduces the balance incorrectly.
Using multiplication or division is not appropriate here.
3fill in blank
hard

Fix the error in the condition to check if the balance is negative.

LLD
if balance [1] 0:
    print('Balance is negative')
Drag options to blanks, or click blank then click option'
A>
B==
C<
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than or equal to checks for positive or zero balances.
Using equality checks only for zero balance.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps account IDs to their balances if balance is positive.

LLD
positive_balances = {account_id: [1] for account_id, [2] in accounts.items() if balance > 0}
Drag options to blanks, or click blank then click option'
Abalance
Caccount_balance
Damount
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causes errors or undefined variables.
Not matching the variable in the condition with the loop variable.
5fill in blank
hard

Fill all three blanks to create a function that calculates the total balance from a list of transactions.

LLD
def calculate_total_balance(transactions):
    total = [1]
    for [2] in transactions:
        total [3]= transaction
    return total
Drag options to blanks, or click blank then click option'
A0
Btransaction
C+
Dbalance
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing total to None or other types causes errors.
Using incorrect loop variable names or operators.