Getting the solution with the max meetings that can fit into a single meeting room

28 Views Asked by At

i have to implement a class named plan that has only one method. The method takes as parametre an array list of objects type Meeting, and modifies the array list mentioned in a way that will contain only the meetings that can be planned into a single room of meetings. The meetings must not overlap, and must be sorted in ascending order after the start date. If there are more solutions with a maxim number of meetings, then we have to find the solution which has the array composed with the end dates of the meetings with the lowest lexicographic end date. In case of equality between end dates, then we have to find the solution with the lowest start date. So in the solution below i succeded to get the solution with the meetings that don t overlap, but i don t how to see if there are more solutions with the max numbers of solution. Here i am stuck. Please help.

class SortByEnding implements Comparator<Meeting> {
    @Override
    public int compare(Meeting m2, Meeting m1) {

        if (m1.getSfarsit().compareTo(m2.getSfarsit()) < 0) {
            return 1;
        }
        if (m1.getSfarsit().compareTo(m2.getSfarsit()) > 0) {
            return -1;
        }

        return 0;
   }
}

class Plan { 
    public static void planMeetings(List<Meeting> meetings) {        
        Collections.sort(meetings, new SortByEnding()); 
        List<Meeting> planned = new ArrayList<>(); 
        int index = 0; 
        long maxTime = 0; 
        planned.add(meetings.get(0)); 
        maxTime = meetings.get(0).getSfarsit().getTimeInMillis(); 
        for (int i = 1; i < meetings.size(); i++) { 
            if (meetings.get(i).getInceput().getTimeInMillis() > maxTime) {                         
            planned.add(meetings.get(i)); 
            maxTime = meetings.get(i).getSfarsit().getTimeInMillis(); 
        } 
        meetings.clear();
        meetings.addAll(planned);
    }    
0

There are 0 best solutions below