Build and Review an Employee Expense Reimbursement Application
Color HealthSoftware Engineer · Technical ScreenLast updated
This problem tests your ability to design a simple RESTful API and implement core CRUD operations with server-side validation for an expense tracking system.
Problem Statement
You are tasked with building the backend logic for an expense reimbursement system. You need to provide an interface to manage expenses, ensuring that business rules are enforced consistently.
Requirements
- Define an
Expensedata model with the following fields:id(int),amount(float),category(string),is_reimbursed(bool), anddescription(string). - Implement a class
ExpenseManagerwith the following methods:add_expense(expense_data): Adds a new expense. Return the created object.delete_expense(expense_id): Removes an expense by ID.list_expenses(): Returns a list of all current expenses.toggle_reimbursement(expense_id): Flips theis_reimbursedstatus.
Business Rules
- An expense cannot be added if the
amountis less than or equal to zero. - A reimbursement status cannot be toggled for an expense that has an amount greater than $1,000 without first triggering an 'approval' flag (for this exercise, simply raise an error if
amount > 1000).
Example
# Input
manager = ExpenseManager()
manager.add_expense({'amount': 50.0, 'category': 'Travel', 'description': 'Uber'})
# Output: Expense(id=1, amount=50.0, ...)
# Input
manager.toggle_reimbursement(1)
# Output: Expense(id=1, is_reimbursed=True, ...)
Edge Cases
- Deleting a non-existent ID.
- Adding expenses with negative values.
- Toggling status for high-value expenses that violate the business rule.
Hints
Hint 1
Use a dictionary or a list to store expense objects in memory for this implementation.
Hint 2
Ensure the `toggle_reimbursement` method performs a lookup first to verify if the expense exists and checks the value constraint before updating.
Hint 3
Consider using an `IdGenerator` or a simple counter to ensure unique IDs for each added expense.
Follow-up questions
- How would you modify the data model to support multi-currency expenses?
- If this system were scaled to millions of expenses, what database optimizations would you implement?
- How would you implement an audit log to track who toggled the reimbursement status and when?
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.