Aggregate expenses by person, trip, and category
Company: Rippling
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
## Problem
You are given a list of expense records. Each record has:
- `employee_id` (string)
- `trip_id` (string)
- `category` (string, e.g., `MEAL`, `HOTEL`, `TRANSPORT`)
- `amount` (integer)
Implement functions to compute aggregated totals:
1) **Per-employee total**
- Return total spend for each `employee_id`.
2) **Per-trip breakdown (for one employee)**
- Given an `employee_id`, return total spend per `trip_id`.
3) **Per-category breakdown (for one employee)**
- Given an `employee_id`, return total spend per `category`.
## Input/Output expectations
- Input: an array/list of expense records.
- Output: maps/dictionaries for each query type.
## Constraints
- Up to 10^6 expense records.
- Aim for efficient time complexity; avoid re-scanning the full list for every query.
Quick Answer: This question evaluates a candidate's ability to perform efficient data aggregation, use associative data structures (maps/dictionaries), and reason about time and space complexity when processing large collections of records.