Skip to content

Instantly share code, notes, and snippets.

@ducalpha
Created January 4, 2016 00:27
Show Gist options
  • Select an option

  • Save ducalpha/87cefd314c9e858acb5c to your computer and use it in GitHub Desktop.

Select an option

Save ducalpha/87cefd314c9e858acb5c to your computer and use it in GitHub Desktop.
Check valid schedule
struct Meeting {
int start, end;
};
struct CompareMeeting {
bool operator()(const Meeting& a, const Meeting& b) const {
if (a.start == b.start) return a.end < b.end;
return a.start < b.start;
}
};
bool IsValidSchedule(vector<Meeting> meetings) {
sort(meetings.begin(), meetings.end(), CompareMeeting);
for (int i = 1; i < meetings.size(); ++i) {
if (meetings[i - 1].end > meeting[i].start)
return false;
}
return true;
} // O(nlogn) time, O(n) space
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment