Model an Extensible Employee Cost Calculator
Company: Amazon
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Onsite
Design an object model and calculation API for the total cost of an employee. Total cost has four components:
1. Base salary from the employee record.
2. Tax as a fixed percentage of base salary.
3. Benefits from a lookup keyed by `(level, title)`.
4. A positive or negative location adjustment from a lookup keyed by location.
Define the necessary types and implement the calculation conceptually. Explain validation, money representation, missing lookup entries, configuration versioning, and tests. The goal is an extensible design, not a hard-coded chain of conditionals.
### Constraints & Assumptions
- All monetary values use one declared currency for a single calculation.
- Tax rate and lookup tables are supplied configuration, not global constants hidden inside the employee class.
- Level, title, and location use canonical identifiers.
- A calculation should be reproducible after compensation rules change.
### Clarifying Questions to Ask
- Is tax truly a single fixed rate, or can it vary by employee or location?
- Should a missing benefit or location rule fail, default to zero, or use a fallback hierarchy?
- Are adjustments annual amounts or percentages?
- What rounding mode and currency precision are required?
### What a Strong Answer Covers
- Separates employee data, policy configuration, lookup interfaces, and calculation output.
- Uses decimal or integer minor-unit money rather than binary floating point.
- Returns a component breakdown as well as the total.
- Makes missing configuration explicit and validates canonical composite keys.
- Versions policy data so results are auditable and reproducible.
- Tests normal, boundary, negative-adjustment, missing-rule, and rounding cases.
### Follow-up Questions
1. How would you support progressive tax brackets without changing callers?
2. How would effective-dated policy changes be applied to historical calculations?
3. What should happen if salary and adjustment inputs use different currencies?
Quick Answer: Model an extensible employee cost calculator combining salary, tax, benefits, and a signed location adjustment. Discuss precise money handling, explicit missing policies, canonical identifiers, versioned configuration, reproducible breakdowns, and boundary-focused tests.