Aggregate expenses by person, trip, and category
RipplingSoftware Engineer · OnsiteLast updated
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.
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:
- Per-employee total
- Return total spend for each
employee_id.
- Per-trip breakdown (for one employee)
- Given an
employee_id, return total spend pertrip_id.
- Per-category breakdown (for one employee)
- Given an
employee_id, return total spend percategory.
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.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.