Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the net balance for each person.
LLD
net_balance = {person: 0 for person in [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using debts or transactions instead of the list of people.
Initializing net_balance with an empty dictionary without keys.
✗ Incorrect
We initialize net_balance for each person in the list people.
2fill in blank
mediumComplete the code to update net balances after each transaction.
LLD
net_balance[debtor] [1]= amount net_balance[creditor] [1]= -amount
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition for debtor's balance which increases it incorrectly.
Using multiplication or division which are not relevant here.
✗ Incorrect
Debtor's balance decreases by amount, creditor's balance increases by amount, so debtor subtracts amount and creditor adds amount (negative subtract equals add).
3fill in blank
hardFix the error in the code to find the person with maximum credit.
LLD
max_credit_person = max(net_balance, key=lambda x: net_balance[[1]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using net_balance or max_credit_person inside the lambda instead of the parameter.
Using a variable not defined in the lambda parameter list.
✗ Incorrect
The lambda function parameter x is used to access net_balance[x].
4fill in blank
hardFill both blanks to correctly update balances after settling debts.
LLD
settle_amount = min(net_balance[[1]], -net_balance[[2]]) net_balance[[1]] -= settle_amount net_balance[[2]] += settle_amount
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping creditor and debtor in the blanks.
Using unrelated variable names.
✗ Incorrect
We settle debts between the person with max credit and max debit.
5fill in blank
hardFill all three blanks to create the final simplified debts record.
LLD
if settle_amount > 0: simplified_debts.append(([1], [2], [3]))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing debtor and creditor in the tuple.
Using net_balance instead of settle_amount for the amount.
✗ Incorrect
The simplified debt is from debtor to creditor with the settled amount.