#458 Finding Overlapping Events

Companies:
VK
Themes:
AlgorithmsSortingPractice

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

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in