The purpose here is to find if there is a conflict in the given set of start and end times of the meeting time slots listed.
Input: Start and end times of meetings
Output: True / False for conflicts
package code.Misc;
import java.util.ArrayList;
public class Calendar {
static int time [] = new int[1440];
public static void main(String args[]){
String s[] = {"15:30","1:30","1:15","15:00"};
String e[] = {"18:35","13:28","1:30","15:29"};
System.out.println(scheduler(s, e));
}
public static int calculateMinute(int hour, int minute){
return hour*60+minute;
}
public static boolean timeClashChecker(int start, int end){
for(int i=start;i<=end;i++){
if(i==end){
time[i] = -1;
}
else if(time[i]==1){
return false;
}
else if(time[i]==-1){
time[i]=1;
}
else{
time[i]=1;
}
}
return true;
}
public static int parser(String time){
String [] timeParts = time.split(":");
int hour = Integer.parseInt(timeParts[0].trim());
int minute = Integer.parseInt(timeParts[1].trim());
return calculateMinute(hour,minute);
}
public static boolean scheduler(String start[], String end[]){
for(int i=0;i<start.length;i++){
int startMeeting = parser(start[i]);
int endMeeting = parser(end[i]);
boolean result = timeClashChecker(startMeeting,endMeeting);
if(result == false){ //clash check
return false;
}
}
return true;
}
}
default calendar
class, might end up calling this or vice versa , may cause you trouble :) \$\endgroup\$