Frontend-flavoured problems · senior
Event scheduling: overlapping calendar events
To lay out a calendar day, sort events by start, group events that overlap into clusters, give each event the first free column in its cluster, and make every event in a cluster 1/columns wide. The same sweep line also answers 'how many rooms' and 'can I attend all'.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Use half-open intervals [start, end) in minutes: 10:00–11:00 and 11:00–12:00 do not overlap.
- Sort by start, then longer events first (end descending) so long events get the left column.
- Cluster: a run of events where each starts before the maximum end seen so far; a new cluster starts when start >= clusterMaxEnd.
- Column assignment: keep each column's last end; place the event in the first column whose last end <= start; else open a new column. A min-heap of (end, column) makes it O(n log n) for big inputs.
- Width = 1 / (columns in the cluster); left = column / columns. Better layouts let an event expand right into free columns — mention as a stretch.
- Max overlap (rooms needed): sweep starts and ends; with ties, process ends first.
- Dates: store UTC instants, display in the user's time zone; all-day and multi-day events go in a separate row; new Date('YYYY-MM-DD') parses as UTC midnight.
The red pen
Common traps: mistake → fix
Mistake: Closed intervals for meetings
Fix: back-to-back meetings would be shown side by side.
Mistake: Width = 1 / (events overlapping this one)
Fix: chains (A overlaps B, B overlaps C) need cluster-wide columns or events will overlap visually.
Mistake: Comparing times as strings ('9:00' > '10:00')
Fix: convert to minutes.
Easy to hard
Questions interviewers ask, easy to hard
- Can a person attend all meetings?
- How many rooms are needed?
- Lay out overlapping events side by side in a day view.
- Make long events expand into empty columns. What changes?
- Events come from many time zones; how do you place them?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.