๐Ÿ’ฐ

Expense Tracker

Track spending by category, with totals, category totals and the biggest expense.

Project 5Intermediate

๐Ÿงฉ Problem statement

Each expense is written as “CATEGORY:AMOUNT:DESCRIPTION”. Show the total spent, the total per category (as a map), and the single highest expense as “DESCRIPTION (AMOUNT)”.

๐Ÿ“‹ Requirements

  • Add expense
  • Category
  • Total
  • Category totals
  • Highest expense
  • Date filter (extension)

๐Ÿ“ฅ Inputs

  • EXPENSES: a list of text entries

๐Ÿ“ค Outputs

  • Total
  • Category totals map
  • Highest expense

๐Ÿ“ Rules

  • Amounts are positive

๐Ÿšง Constraints

  • At least one expense

๐Ÿงญ Suggested approach

  • Split each entry
  • Accumulate the total
  • Accumulate per category in a map
  • Track the maximum

๐Ÿง  Required concepts

  • Maps
  • Strings
  • Accumulators
  • Min/max
โœ๏ธ Pseudocode editor ยท dry-run tool ยท test cases

Design your solution here. Use Run to dry-run it step by step and Run tests to check it. Hints unlock one at a time โ€” try on your own first!

๐Ÿงช Edge cases to test

  • A single expense
  • Two expenses with the same highest amount
  • Many categories

๐Ÿ“ˆ Complexity analysis

O(n) time; O(c) memory for c categories.

๐Ÿ“– Solution walkthrough (open after youโ€™ve tried!)

One pass does three jobs at once: a running total, a per-category total using the map-counting pattern (but adding amounts), and a best-so-far for the highest expense. NUMBER turns the amount text into a number so the maths works.

๐Ÿš€ Challenge extensions

  • Add dates ("2026-09-01") and total per month
  • Show categories sorted from highest to lowest
  • Warn when a category exceeds a budget

โ† All projects