Question presented to candidate: "We are a hotel booking site. Build the check-in / check-out calendar: two months side by side, the guest clicks a start date and an end date, and while they move the mouse we preview the stay. Some nights are already booked, and a stay can never include one. Tell the guest how many nights they picked, and make it work from the keyboard."
Requirements:
- Two consecutive months visible, with previous / next navigation and a
min/maxwindow. - First pick sets check-in, second pick sets check-out; a pick before check-in restarts the range; a completed range restarts on the next pick.
- While choosing check-out, hovering or keyboard-focusing a day previews the range up to that day.
- Booked dates are not selectable, and the preview and check-out are capped at the night before the next booked date.
- A live status line: the next step, the latest allowed check-out, and finally "Tue, Mar 3 to Mon, Mar 9, 6 nights".
- Keyboard: arrows, Home / End, PageUp / PageDown move focus across both months (the view scrolls when focus leaves it), Enter selects, Escape cancels a half-made range. Emit
[start, end]when complete.
What a strong answer should cover:
- A small selection state machine (no start, choosing end, complete) and a pure
pick(range, day)function. - Deriving cell states (start, end, in range, preview, unavailable) during render instead of storing them.
- Capping the range at the first blocked date after check-in (
maxEnd), and disabling every later day while choosing. - Counting nights with UTC day arithmetic: local midnights across a DST change are 23 or 25 hours apart, so dividing by 86,400,000 and rounding down with
Math.flooris wrong. - A roving tabindex that spans two grids, focus-driven preview for keyboard users,
aria-selectedon the range and a polite live region.
Clarifying questions expected:
- "Is the minimum stay one night, and is there a maximum stay?"
- "Can check-out fall on a booked date (the guest leaves that morning), or must every day of the range be free?"
- "Should clicking a date earlier than check-in move check-in, or swap the two?"
Code / implementation expected: Yes. A working two-month range picker; it may reuse the single-date picker's date helpers.