0
0
LLDsystem_design~10 mins

Simplify debts 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 net balance for each person.

LLD
net_balance = {person: 0 for person in [1]
Drag options to blanks, or click blank then click option'
Atransactions
Bpeople
Cdebts
Dbalances
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.
2fill in blank
medium

Complete 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'
A-
B/
C*
D+
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.
3fill in blank
hard

Fix 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'
Amax_credit_person
Bperson
Cnet_balance
Dx
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.
4fill in blank
hard

Fill 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'
Amax_credit_person
Bmax_debit_person
Cdebtor
Dcreditor
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping creditor and debtor in the blanks.
Using unrelated variable names.
5fill in blank
hard

Fill 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'
Amax_debit_person
Bmax_credit_person
Csettle_amount
Dnet_balance
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing debtor and creditor in the tuple.
Using net_balance instead of settle_amount for the amount.