Bird
0
0

How would you design the Expense class to support splitting costs unevenly among users?

hard📝 Trade-off Q9 of 15
LLD - Design — Splitwise (Expense Sharing)
How would you design the Expense class to support splitting costs unevenly among users?
AStore only total amount and divide equally in split method
BAdd a dictionary mapping users to their share amounts
CAdd a list of users without share details
DKeep a single user as payer and ignore others
Step-by-Step Solution
Solution:
  1. Step 1: Understand uneven split requirement

    Uneven splits require tracking each user's specific share.
  2. Step 2: Choose data structure to map users to shares

    A dictionary mapping users to amounts fits this need well.
  3. Final Answer:

    Add a dictionary mapping users to their share amounts -> Option B
  4. Quick Check:

    Uneven split needs user-to-share mapping [OK]
Quick Trick: Use dictionary to map users to their shares [OK]
Common Mistakes:
  • Assuming equal split always
  • Ignoring share details per user
  • Using list without share info

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes