Stripe·Software Engineer·Technical Phone Screen
- Write a function that takes a list of line items (each with a product ID and quantity) and a price lookup dictionary, then returns the total cost and a per-item breakdown. What do you do when a product ID isn't in the price dictionary?
- Extend the function with input validation: quantities and prices must be numeric and non-negative, NaN and infinity should be rejected, and invalid rows should produce clear error messages. Also handle empty input and duplicate product IDs.
- Add an optional sort parameter so that when enabled, the breakdown is returned sorted by per-item cost in descending order using a lambda. Document your rounding rules and make sure the output matches expected results.
“The missing product ID edge case is where I spent way too long deliberating.”