Skip to main content

Design a Meeting Scheduler System

Problem Statement

Design a meeting scheduler system that allows users to create meetings, invite participants, and check availability before confirming a meeting. The system should prevent overlapping meetings for any participant and should maintain a schedule for each user.


Functional Requirements

  • Users should be able to schedule meetings with a start and end time
  • System should prevent overlapping meetings for any participant
  • Users can invite multiple participants to a meeting
  • Each user should maintain their own meeting calendar
  • System should allow cancellation of meetings
  • Cancelled meetings should free up participant schedules

Objects Required

  • User
  • Meeting
  • Calendar
  • TimeSlot
  • MeetingSchedulerService

TimeSlot Class


public class TimeSlot {

    private String startTime;
    private String endTime;

    public TimeSlot(String startTime, String endTime) {
        this.startTime = startTime;
        this.endTime = endTime;
    }

    public boolean overlaps(TimeSlot other) {

        return !(this.endTime.compareTo(other.startTime) <= 0 ||
                 this.startTime.compareTo(other.endTime) >= 0);
    }
}

The constructor initializes a time slot with a start and end time, which represents a scheduled interval for a meeting.

The overlaps() method checks whether two time intervals conflict. It ensures that no two meetings can occupy the same time window for a user, which is the core rule of the scheduler.


Meeting Class


import java.util.*;

public class Meeting {

    private String meetingId;
    private TimeSlot timeSlot;
    private List participants;

    public Meeting(String meetingId, TimeSlot timeSlot, List participants) {
        this.meetingId = meetingId;
        this.timeSlot = timeSlot;
        this.participants = participants;
    }

    public TimeSlot getTimeSlot() {
        return timeSlot;
    }

    public List getParticipants() {
        return participants;
    }
}

The constructor creates a meeting with a time slot and a list of participants.

The getTimeSlot() method exposes the scheduled time so it can be validated against user calendars.

The getParticipants() method returns all invited users so their calendars can be updated consistently.


Calendar Class


import java.util.*;

public class Calendar {

    private List meetings = new ArrayList<>();

    public boolean canSchedule(TimeSlot slot) {

        for (Meeting meeting : meetings) {
            if (meeting.getTimeSlot().overlaps(slot)) {
                return false;
            }
        }
        return true;
    }

    public void addMeeting(Meeting meeting) {
        meetings.add(meeting);
    }

    public void removeMeeting(Meeting meeting) {
        meetings.remove(meeting);
    }
}

The constructor initializes an empty calendar for each user.

The canSchedule() method ensures that a new meeting does not conflict with existing meetings. This is the core validation step that prevents double-booking.

The addMeeting() method adds a confirmed meeting to the user’s calendar.

The removeMeeting() method removes a meeting when it is cancelled, freeing up the time slot.


User Class


public class User {

    private String userId;
    private String name;
    private Calendar calendar;

    public User(String userId, String name) {
        this.userId = userId;
        this.name = name;
        this.calendar = new Calendar();
    }

    public Calendar getCalendar() {
        return calendar;
    }
}

The constructor initializes a user along with their personal calendar, which stores all their scheduled meetings.

The getCalendar() method allows the scheduler service to check availability and update meetings for that user.


MeetingSchedulerService Class


import java.util.*;

public class MeetingSchedulerService {

    public Meeting scheduleMeeting(String meetingId,
                                   TimeSlot slot,
                                   List users) {

        for (User user : users) {
            if (!user.getCalendar().canSchedule(slot)) {
                System.out.println("User not available: " + user);
                return null;
            }
        }

        Meeting meeting = new Meeting(meetingId, slot, users);

        for (User user : users) {
            user.getCalendar().addMeeting(meeting);
        }

        return meeting;
    }

    public void cancelMeeting(Meeting meeting) {

        for (User user : meeting.getParticipants()) {
            user.getCalendar().removeMeeting(meeting);
        }

        System.out.println("Meeting cancelled successfully");
    }
}

The constructor is implicit since this service does not maintain state and only coordinates scheduling logic.

The scheduleMeeting() method first validates availability for all participants. If even one user is busy, the meeting is rejected to maintain consistency across calendars. If all users are free, the meeting is created and added to every participant’s calendar.

The cancelMeeting() method removes the meeting from all participant calendars, ensuring the time slot becomes available again.


Main Class


import java.util.*;

public class Main {

    public static void main(String[] args) {

        User u1 = new User("U1", "Alice");
        User u2 = new User("U2", "Bob");

        TimeSlot slot = new TimeSlot("10:00", "11:00");

        MeetingSchedulerService service = new MeetingSchedulerService();

        Meeting meeting = service.scheduleMeeting(
                "M1",
                slot,
                Arrays.asList(u1, u2)
        );

        if (meeting != null) {
            System.out.println("Meeting scheduled successfully");
        }

        service.cancelMeeting(meeting);
    }
}

The main method demonstrates a full scheduling flow starting from user creation to meeting scheduling and cancellation.

It shows how the system ensures no overlapping meetings while keeping all participant calendars in sync.


Class Diagram

UseruserId : Stringname : Stringcalendar : CalendarCalendarmeetings : List<Meeting>canSchedule(slot) : booleanaddMeeting(meeting) : voidremoveMeeting(meeting) : voidMeetingmeetingId : StringtimeSlot : TimeSlotparticipants : List<User>getTimeSlot() : TimeSlotgetParticipants() : List<User>TimeSlotstartTime : StringendTime : Stringoverlaps(slot : TimeSlot) : booleanMeetingSchedulerServicescheduleMeeting(id, slot, users) : MeetingcancelMeeting(meeting : Meeting) : void

Comments

Popular posts from this blog

Designing a Parking Lot - Low Level Design

Problem Statement Design a parking lot that can handle vehicles entering and leaving while managing parking across multiple floors. Each vehicle should be assigned a suitable parking spot based on its type, and the spot should be freed once the vehicle exits. The design should also support generating a ticket at entry and optionally calculating the parking fee based on the duration of stay. Asked In Companies Amazon Google Microsoft Uber Walmart Flipkart Meta PayPal Oracle Salesforce Adobe Apple Intuit LinkedIn Atlassian Functional Requirements The design should support multiple vehicle types such as bikes, cars, and trucks A vehicle must be assigned a parking spot compatible with its type A parking spot cannot be assigned to more than one vehicle at a time The parking lot should support multiple levels (floors) The design should search and allocate an availa...

Most Frequently Asked Low Level Design(LLD) Interview Questions

Below are the curated list of most commonly asked Low Level Design (LLD) interview problems. Each problem includes a short description and a link to the complete solution with code and class diagrams. Design Parking Lot System The system should handle parking for different vehicle types such as bikes, cars, and trucks. It should manage slot allocation, availability tracking, and entry/exit flow. The design also ensures efficient usage of parking space under varying load conditions. View Solution Design Elevator / Lift System The system should support multiple elevators operating across floors with request handling logic. It focuses on scheduling algorithms to minimize wait time and optimize movement. It also manages direction control and concurrent floor requests. View Solution Design Movie Ticket Booking System The system should allow users to browse movies, select shows, and book seats. It handles seat ...

Software Design Patterns for LLD Interviews: A Complete Guide

Software Design Patterns for LLD Interviews: A Complete Guide In Software Development Engineer (SDE) interviews—especially for mid-level and senior roles—low-level design (LLD) rounds assess your ability to write clean, reusable, maintainable, and extensible code. The foundation of resolving these architectural challenges lies in the standard Gang of Four (GoF) Design Patterns. Rather than memorizing theoretical definitions, interviewers expect you to apply these patterns to real-world scenarios, identifying the trade-offs of each. Below is a comprehensive guide to the 12 most frequently asked design patterns in LLD interviews, categorized by their classification (Creational, Structural, and Behavioral). Each pattern contains a concrete, real-world Java implementation and a detailed breakdown of design decisions. Creational Design Patterns Creational design patterns deal with object creation mechanisms. They abstract the instantiation process, making a system independent of how...