As reported: Wayfair software engineer loop (2026), round 2 (coding): given a coupon table and a category table, write
getCouponForCategory(categoryName); follow-up: a category can have several coupons, each with a modified date. The loop also had an OA and a low-level design round.
You are given two data sets:
- Coupons —
{CategoryName, CouponName} - Categories —
{CategoryName, CategoryParentName}; a top-level category has anullparent.
Write a function that, given a category name, returns the name of the coupon to display for it.
- The category structure is hierarchical: a category without a coupon inherits its parent's coupon (and so on up the tree).
- If a category has a coupon, return it — do not move up to the parent.
- If no category in the chain has a coupon, return no coupon (
null).
Example
Coupons
Comforter Sets -> "Comforters Sale"
Bedding -> "Savings on Bedding"
Bed & Bath -> "Low price for Bed & Bath"
Categories (category -> parent)
Comforter Sets -> Bedding
Bedding -> Bed & Bath
Bed & Bath -> null
Soap Dispensers -> Bathroom Accessories
Bathroom Accessories -> Bed & Bath
Toy Organizers -> Baby And Kids
Baby And Kids -> null
getCouponForCategory("Comforter Sets") -> "Comforters Sale" (its own coupon, not Bedding's)
getCouponForCategory("Bedding") -> "Savings on Bedding"
getCouponForCategory("Bathroom Accessories") -> "Low price for Bed & Bath" (inherited)
getCouponForCategory("Soap Dispensers") -> "Low price for Bed & Bath"
getCouponForCategory("Toy Organizers") -> null (no coupon in its hierarchy)
Follow-up: several coupons per category
Each coupon now also has a DateModified, and one category can have two or more coupons. Return one coupon name:
- If a category has more than one coupon, return the one with the most recent
DateModified. - A coupon whose
DateModifiedis in the future must not be returned. - Categories without coupons still inherit their parent's coupon.
Coupons (category, coupon, DateModified)
Comforter Sets "Comforters Sale" 2020-01-01
Comforter Sets "Cozy Comforter Coupon" 2020-01-01
Bedding "Best Bedding Bargains" 2019-01-01
Bedding "Savings on Bedding" 2019-01-01
Bed & Bath "Low price for Bed & Bath" 2018-01-01
Bed & Bath "Bed & Bath extravaganza" 2019-01-01
Bed & Bath "Big Savings for Bed & Bath" 2030-01-01 (future)
Same category tree.
getCouponForCategory("Bed & Bath") -> "Bed & Bath extravaganza"
getCouponForCategory("Bedding") -> "Best Bedding Bargains" or "Savings on Bedding"
getCouponForCategory("Bathroom Accessories") -> "Bed & Bath extravaganza"
getCouponForCategory("Comforter Sets") -> "Comforters Sale" or "Cozy Comforter Coupon"
Clarifications
- "Today" is passed in; a coupon dated exactly today is not in the future.
- A category whose coupons are all in the future counts as having no coupon, so it inherits from its parent.
- When several coupons share the most recent date, any of them is a correct answer; the code runner expects the one listed first in
coupons. - A category that does not appear in
categorieshas no parent; it still gets its own coupon if it has one. - The category data has no cycles.
Constraints: up to 2000 categories, 2000 coupons and 2000 queries; dates are YYYY-MM-DD.
Code runner format: four lines, one JSON value each: coupons as [category, coupon, dateModified] triples, categories as [category, parent] pairs (parent is null for a top-level category), today, and the list of category names to query. Implement the class CouponFinder(coupons, categories, today) with getCouponForCategory(categoryName) returning the coupon name or null ("" in C++ and Go); the harness prints the answers as a JSON list.