Design a coupon redemption system
Company: Plaid
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Implement an in-memory coupon service supporting: addCoupon(code, discount, expiresAt, totalLimit, perUserLimit); redeem(userId, code, now) -> success/discountApplied; and getRemaining(code, now). Choose data structures to achieve O(
1) average lookups and updates (e.g., hash maps plus a structure for expirations). Analyze time/space complexity. Handle edge cases: invalid or duplicate codes, expired coupons, zero/negative discounts, exceeding global/per-user limits, clock skew/daylight-saving near expiresAt, and idempotent retries. Follow-up: extend to support category restrictions, minimum spend thresholds, and bulk input parsing.
Quick Answer: This question evaluates proficiency in data structures and algorithms for building an in-memory service, including efficient lookup/update strategies, expiration handling, limit enforcement, idempotency, concurrency considerations, and time/space complexity reasoning.