Planning a meeting

0

0 votes
Algorithms, Basics of Greedy Algorithms, Greedy Algorithms
Problem

You have to organize meetings today. There are N meetings for today. Meeting i must start at time start[i] and end at time end[i]. Unfortunately, there are only two meeting rooms available today. Consider meetings a and b intersecting in time if max(start[a], start[b])min(end[a], end[b]).

You cannot conduct two meetings in the same room at the same time.

Your task is to determine whether it is possible to hold all meetings using only two rooms. If yes, then print 1. Otherwise, print 0.

Function description

Complete the isPossible function in the editor. It contains the following parameters:

  1. Parameter name: n
    • Type: INTEGER
    • Description: Number of meetings
  2. Parameter name: start
    • Type: INTEGER ARRAY
    • Description: Start time of meetings
  3. Parameter name: end
    • Type: INTEGER ARRAY
    • Description: End time of meetings
  4. Return
    • The function must return an INTEGER denoting the answer to the problem. 
    • If it is possible to hold all the meetings using only two rooms, then it is 1. Otherwise, it is 0.

Input format 

  • The first line contains an integer n denoting the number of elements in start.
  • Each line i of n subsequent lines (where 0i<n) contains an integer describing starti.
  • Each line i of n subsequent lines (where 0i<n) contains an integer describing endi.

Constraints

1n1051start[i]1081end[i]108

Sample Input
3
1
2
4
2
3
5

Sample Output
1
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

Hold the first ([1; 2]) and the third ([4; 5]) meetings in the first room.

Hold the second meeting ([2; 3]) in the second room.

Contributers:
Editor Image

?