KatInterview

Build a Lodging Booking Widget with Correct Pricing

System DesignModel answer
MediumModel answerSystem Designfrontendstate-managementpricing

Last updated

Design and implement a reservation widget: date/guest inputs, dynamic price breakdown, validation, disabled booking on invalid or sold-out stays, and a confirm dialog.

You are asked to build a small booking widget for a single rental listing. It must:

  1. Accept a check-in date, a check-out date, and guest counts (adults and children). Compute a total price that reflects a night-by-night rate, the number of nights, and per-guest surcharges that kick in above the listing's included occupancy.
  2. Validate the selection: check-out must be strictly after check-in, check-in cannot be in the past, the stay must respect minimum and maximum night counts, every night in the stay must be available, at least one adult is required, and adults plus children must not exceed capacity.
  3. Keep a "Book Now" button disabled whenever the selection is invalid or the listing has no availability.
  4. Show a confirmation dialog on submit and only finalize after the user confirms.

Explain your component state, the domain data models, the derived vs. stored values, and your error states. Then walk through how you would test edge cases: minimum-night rules, partially available ranges, timezone and daylight-saving transitions, and rounding of prices and tax. Provide code for the core logic.

Hints

Hint 1

Separate pure domain functions (validate, price) from the UI shell so you can unit-test them without rendering anything.

Hint 2

Treat a stay as a list of nights from check-in inclusive to check-out exclusive, and represent dates as calendar dates, not timestamps.

Hint 3

Store money in integer cents and round exactly once at the tax step with an explicit rule.