0
0
LLDsystem_design~10 mins

Why Splitwise tests financial logic in LLD - Test Your Understanding

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

Complete the code to calculate the total amount owed by a user.

LLD
total_owed = sum(expense.amount for expense in user.expenses if expense.paid_by != [1])
Drag options to blanks, or click blank then click option'
Auser.id
Bexpense.id
Cexpense.paid_by
Duser.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using the expense ID instead of the payer's ID.
Comparing with user name instead of user ID.
2fill in blank
medium

Complete the code to split an expense evenly among participants.

LLD
share = expense.amount / [1]
Drag options to blanks, or click blank then click option'
Asum(expense.participants)
Bexpense.amount
Cexpense.paid_by
Dlen(expense.participants)
Attempts:
3 left
💡 Hint
Common Mistakes
Dividing by the amount itself.
Using the payer instead of participants count.
3fill in blank
hard

Fix the error in the code that calculates the balance for each user.

LLD
balance = user.paid_amount - sum(user.owed_amounts.get([1], 0) for user in users)
Drag options to blanks, or click blank then click option'
Auser.name
Buser.id
Cexpense.id
Duser.paid_amount
Attempts:
3 left
💡 Hint
Common Mistakes
Using user.name which may not be unique.
Using expense.id which is unrelated.
4fill in blank
hard

Fill both blanks to create a dictionary of user balances where keys are user IDs and values are their net balances.

LLD
balances = {user.[1]: user.[2] for user in users}
Drag options to blanks, or click blank then click option'
Aid
Bbalance
Cname
Dpaid_amount
Attempts:
3 left
💡 Hint
Common Mistakes
Using user names as keys which may not be unique.
Using paid_amount instead of balance for values.
5fill in blank
hard

Fill all three blanks to filter expenses where the amount is greater than zero and the payer is not the current user.

LLD
filtered_expenses = [expense for expense in expenses if expense.[1] > [2] and expense.[3] != current_user.id]
Drag options to blanks, or click blank then click option'
Aamount
B0
Cpaid_by
Duser_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using user_id instead of paid_by for payer.
Checking amount less than zero.