Problem of the day
You are given the schedule of 'N' meetings with their start time 'Start[i]' and end time 'End[i]'.
You have only 1 meeting room. So, you need to return the maximum number of meetings you can organize.
The start time of one chosen meeting can’t be equal to the end time of the other chosen meeting.
'N' = 3, Start = [1, 3, 6], End = [4, 8, 7].
You can organize a maximum of 2 meetings. Meeting number 1 from 1 to 4, Meeting number 3 from 6 to 7.
The first line contains a single integer 'N', denoting the number of meetings.
The second line contains 'N' single space-separated integers denoting the start time of 'N' meetings, respectively.
The third line contains 'N' single space-separated integers denoting the end time of 'N' meetings, respectively.
Output Format:
The only contains the maximum number of meetings you can organize.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
6
1 3 0 5 8 5
2 4 6 7 9 9
4
You can organize a maximum of 4 meetings:
Meeting number 1 from 1 to 2.
Meeting number 2 from 3 to 4.
Meeting number 4 from 5 to 7.
Meeting number 5 from 8 to 9.
5
0 7 1 4 8
2 9 5 9 10
2
1 <= 'N' <= 10^5
0 <= 'Start[i]' < 'End[i]' <= 10^9
Time Limit: 1 sec
The idea is to choose the meetings greedily.
O(N * logN), where N is the number of meetings.
In the worst case, we are traversing the input arrays once which takes O(N) time and we are sorting the MEETING array of size N which takes O(N * log(N)) time. Thus the final time complexity is O(N) + O(N * log(N)) = O(N * log(N)).
O(N), where N is the number of meetings.
In the worst case, we are creating a MEETING array of size N.