Live Coding Exercise — Personal Finance Tracker
Target language: Scala. Time-box: ~45 minutes. Pair-programming format.
Context
You're contributing to the analytics module of a personal finance app.
The team is shipping a feature that surfaces, at the end of each month,
where users overspent and which category drives the most spending across
the user base.
The two questions below capture the entire scope of the exercise. Solve
them as a single program: input arrives in memory (you can hard-code the
sample dataset or read it from any source you prefer), output goes to
standard output in a format you find readable.
Domain
- A user has a name and a set of monthly budgets, one per spending category.
- A budget is the maximum amount the user wants to spend in a given category during the month.
- An expense is a single recorded transaction belonging to one user, in one category, for a positive amount.
- Categories are pre-defined values (`groceries`, `travel`, `entertainment`, `coffee`, `utilities`).
- Amounts are in the same currency throughout; treat them as decimal values, not floats.
What to compute
-
Per-user budget overages.
For every user, list the categories in which their total monthly spending
strictly exceeds the budget they set, together with the overage amount
(spent − budget). Categories that came in at or under budget are not reported.
-
Top spending category.
Across all users combined, identify the single category with the
highest total spending, and report that total.
Clarifications
- A user may record several expenses in the same category in the same month — they all contribute to the monthly total for that category.
- A user may spend in a category for which no budget was set. That spending counts toward the global category total, but does not produce an overage entry for that user.
- If two categories tie for the highest total, either is an acceptable answer; please mention how you'd extend the rule if asked.
- Expenses always carry a positive amount. You don't need to model refunds, currency conversion, or partial-month proration.
Sample dataset
Users and monthly budgets
| User | Category | Budget |
| Alice | groceries | $300 |
| Alice | entertainment | $100 |
| Alice | transport | $80 |
| Bob | groceries | $250 |
| Bob | travel | $500 |
| Carla | groceries | $200 |
| Carla | entertainment | $60 |
Recorded expenses for the month
| User | Category | Amount |
| Alice | groceries | $180 |
| Alice | groceries | $140 |
| Alice | entertainment | $150 |
| Alice | transport | $60 |
| Bob | groceries | $280 |
| Bob | groceries | $50 |
| Bob | travel | $400 |
| Bob | coffee | $35 |
| Carla | groceries | $220 |
| Carla | entertainment | $75 |
| Carla | entertainment | $20 |
Expected output
Per-user budget overages
- Alice
- groceries: spent $320, budget $300 → over by $20
- entertainment: spent $150, budget $100 → over by $50
- Bob
- groceries: spent $330, budget $250 → over by $80
- Carla
- groceries: spent $220, budget $200 → over by $20
- entertainment: spent $95, budget $60 → over by $35
(Bob's coffee spending of $35 is not an overage because no budget was set for it.
Alice's transport came in at $60 against an $80 budget, so it is not reported.)
Top spending category across all users
- groceries — total spent: $180 + $140 + $280 + $50 + $220 = $880