#458 Finding Overlapping Events
There is a list of events. Each event has an id, a start time, and an end time.
Create an algorithm that determines whether any events conflict, meaning their time intervals overlap.
If the start time of one event equals the end time of another, the events are considered overlapping.
Examples:
Input: [{id="1", startTime=1, endTime=5}, {id="2", startTime=4, endTime=7}]
Output: true
Input: [{id="1", startTime=1, endTime=5}, {id="2", startTime=7, endTime=9}, {id="3", startTime=4, endTime=7}]
Output: true
Input: [{id="1", startTime=1, endTime=5}, {id="2", startTime=6, endTime=7}]
Output: false
Input: []
Output: false
public class ConflictFinder {
public boolean findConflicts(List<Event> events) {
return false; // TODO
}
public static class Event {
private final String id;
private final long startTime;
private final long endTime;
public Event(String id, long startTime, long endTime) {
this.id = id;
this.startTime = startTime;
this.endTime = endTime;
}
public String getId() {
return id;
}
public long getStartTime() {
return startTime;
}
public long getEndTime() {
return endTime;
}
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor