Algorithm to FindMeetingQuery works - #16
Conversation
| conflicts.remove(end); | ||
| } | ||
| else { | ||
| end++; |
There was a problem hiding this comment.
You can just break here. Since your events are sorted, if any events overlap then they will be adjacent. So if element n doesn't overlap, then you know for certain elements n+1 (and so on) won't overlap either. This changes this chunk of code from being O(n^2) to being O(n)
| return free; | ||
| } | ||
|
|
||
| int start = 0; int end; |
There was a problem hiding this comment.
nit: name these current and next. Next should always just be start + 1 since you should only be evaluating adjacent events (see later comment).
| end++; | ||
| } | ||
| } | ||
| start = end; |
There was a problem hiding this comment.
This should be start++. As per the previous comment, end should only ever be equal to start + 1
| start = TimeRange.START_OF_DAY; | ||
| end = conflicts.get(i).start(); |
There was a problem hiding this comment.
Don't re-use variables like this. It makes code hard to read.
There was a problem hiding this comment.
Especially because previously start and end were indexes, and now they're times of the day.
| } | ||
| // after last conflict | ||
| else if (i == conflicts.size()) { |
There was a problem hiding this comment.
nit: write else and else if like:
...
} else if (...) {
// Comment
...
} else {
// Comment
...
}
| } | ||
| // after last conflict | ||
| else if (i == conflicts.size()) { | ||
| System.out.println(" adding last interval "); |
There was a problem hiding this comment.
Remove debug statement.
Given events, meeting duration, and people who need to attend the meeting, finds available times so that everyone can attend the meeting. All tests work. The pseudo code is as follows: