class User {
String id,
String name
}class TimeSlot {
int start,
int end,
boolean overlaps(TimeSlot other) {
// core logic
return this.start < other.end && other.start < this.end;
}
}class Meeting {
String id,
List<User> participants
TimeSlot timeSlot;
}“I model meetings with time slots and participants.
While scheduling a new meeting, I compare it with existing meetings.
If time overlaps and at least one participant is common, I reject it.”
Knows all meetings
Decides whether a new meeting is allowed
class MeetingScheduler {
List<Meeting> meetings = new ArrayList<>();
boolean schedule(Meeting newMeeting){
for(Meeting existing: meetings){
// check conflict
if(hasConflict(existing,newMeeting)) return false;
}
meetings.add(newMeeting)
return true;
}
private boolean hasConflict(Meeting m1, Meeting m2) {
if (!m1.timeSlot.overlaps(m2.timeSlot)) return false;
Set<String> users = new HashSet<>();
for (User u : m1.participants) users.add(u.id);
for (User u : m2.participants) {
if (users.contains(u.id)) return true;
}
return false;
}