Skip to content

Algorithm to FindMeetingQuery works - #16

Open
gracetian6 wants to merge 10 commits into
masterfrom
GraceDev
Open

Algorithm to FindMeetingQuery works#16
gracetian6 wants to merge 10 commits into
masterfrom
GraceDev

Conversation

@gracetian6

Copy link
Copy Markdown
Owner

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:

  • find all conflicts of required attendees
  • sort these conflicts by start time
  • modify conflicts so all events are disjoint
  • return available times as events between disjoint conflicts

conflicts.remove(end);
}
else {
end++;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be start++. As per the previous comment, end should only ever be equal to start + 1

Comment on lines +81 to +82
start = TimeRange.START_OF_DAY;
end = conflicts.get(i).start();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't re-use variables like this. It makes code hard to read.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially because previously start and end were indexes, and now they're times of the day.

Comment on lines +83 to +85
}
// after last conflict
else if (i == conflicts.size()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug statement.

@jessicaslaughter
jessicaslaughter removed their request for review July 13, 2020 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants