Use button to copy the exercise in MD format

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

What to compute

  1. 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.
  2. Top spending category. Across all users combined, identify the single category with the highest total spending, and report that total.

Clarifications

Sample dataset

Users and monthly budgets

UserCategoryBudget
Alicegroceries$300
Aliceentertainment$100
Alicetransport$80
Bobgroceries$250
Bobtravel$500
Carlagroceries$200
Carlaentertainment$60

Recorded expenses for the month

UserCategoryAmount
Alicegroceries$180
Alicegroceries$140
Aliceentertainment$150
Alicetransport$60
Bobgroceries$280
Bobgroceries$50
Bobtravel$400
Bobcoffee$35
Carlagroceries$220
Carlaentertainment$75
Carlaentertainment$20

Expected output

Per-user budget overages

(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