Question presented to candidate: "Show one day of a calendar, like Google Calendar's day view, from 8 am to 7 pm. Each event is a box whose top and height come from its start and end time. When events overlap they must sit side by side, never on top of each other, and they should use as much width as they can. Let me add and delete events and see the layout update."
Requirements:
- A vertical timeline with hour lines; each event positioned by time (
top,height) and by column (left,width). - Overlapping events never cover each other; an event that touches another (one ends at 10:30, the next starts at 10:30) does not count as overlapping.
- Events that do not overlap anything use the full width; within a group, an event expands right into free columns.
- Clicking an event shows its details with a Delete button; a small form adds an event and validates it (title, end after start, inside the visible hours).
- Events are keyboard reachable in time order and have readable labels such as "Interview, 11:00 to 12:00".
What a strong answer should cover:
- The layout as a pure function from events to
{ col, cols, span }, kept out of the components and derived on every change. - Sorting by start (longer first on ties), sweeping into clusters of transitively overlapping events, and greedy column assignment (first column whose last event has ended).
- Why every event in a cluster shares the cluster's column count, and how the right-expansion check works.
- A tricky test set: a chain of overlaps, an event touching a cluster boundary, equal start times, an event that can span two columns.
- Complexity: O(n log n) sort plus a sweep; fine for a day of events.
Clarifying questions expected:
- "Do touching events (end equals start) count as overlapping?"
- "Should a lone event in a busy cluster expand to the right, or keep its narrow column?"
- "Are there all-day or multi-day events, and what is the visible time range?"
Code / implementation expected: Yes. The layout function plus a rendered day view; verifying no two boxes overlap is a plus.