Scheduler
Sort events by start time, detect clashes and find free slots in a day.
๐งฉ Problem statement
Events are “NAME:START:END” with whole hours (9 to 17). Show the events sorted by start time as “START-END NAME”, then every clash as “Clash: A and B” (two events clash if they overlap), then the free hours between 9 and 17.
๐ Requirements
- Events
- Dates & times (hours)
- Conflicts
- Availability
- Sorting
๐ฅ Inputs
- EVENTS: list of "name:start:end"
๐ค Outputs
- Sorted schedule
- Clashes
- Free hours
๐ Rules
- Events overlap if A.start < B.end and B.start < A.end
- The working day is 9โ17
๐ง Constraints
- Up to ~50 events
๐งญ Suggested approach
- Parse into records
- Sort by start (insertion sort)
- Compare every pair for overlap
- Mark busy hours in a list of 24 flags
๐ง Required concepts
- Records
- Sorting
- Nested loops
- Lists
Design your solution here. Use Run to dry-run it step by step and Run tests to check it. Hints unlock one at a time โ try on your own first!
๐งช Edge cases to test
- Events that touch but donโt overlap (10โ11 and 11โ12)
- A fully booked day
- No events
๐ Complexity analysis
Parsing O(n), insertion sort O(nยฒ), clash check O(nยฒ), free hours O(8n).
๐ Solution walkthrough (open after youโve tried!)
Each event is parsed into a record, then insertion sort orders them by start time. Every pair is checked with the standard overlap test โ note that 10โ11 and 11โ12 do NOT overlap, because one ends exactly when the other starts. Finally each working hour is checked against all events to list the free hours.
๐ Challenge extensions
- Support minutes ("9:30")
- Suggest the first free slot of a given length
- Handle several days