Meeting
Ninja is organizing a meeting in an office that starts at a time ‘0’ and will end at a time ‘LAST’. There are ‘N’ presentations that are going to take place in that meeting whose start and end times are given, i.e., ‘ith’ presentation starts at ‘START[i]’ and ends at ‘END[i]’. The presentations don’t overlap with each other. Ninja wants to reschedule at most ‘K’ presentations keeping the original order intact so that the longest period in which there is no presentation scheduled during the meeting is maximized.
Since Ninja is busy with other office work, your task is to help Ninja to reschedule at most ‘K’ presentations.
Note:
The presentation’s duration can’t be changed. You can only change the start and end times.
Input Format:
The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the T test cases follow.
The first line of each test case contains three positive integers, ‘N’, ‘K’, and ‘LAST’, as described in the problem statement.
The following ‘N’ line of each test case contains two non-negative integers denoting ‘start’ and ‘end’ time of ith presentation.
Output Format:
For each test case, print the duration of the longest period in which there is no presentation scheduled during the meeting after rescheduling, not more than ‘K’ meetings.
Output for each test case will be printed in a separate line.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10
1 <= N <= 5000
0 <= K <= N
0 <= LAST <= 10^9
START[i] < END[i], for 1 <= i <= N.
END[i] <= START[i+1], for 1 <= i < N.
Time Limit: 1 second
CodingNinjas
author
2y
Brute Force Approach
Algorithm:
- The idea here is to find the maximum sum subarray of size ‘K+1’, where the array will contain empty slots.
- First, we create an array named emptySlots[], to store the time...read more
CodingNinjas
author
2y
Sliding Window Approach
Algorithm:
- The idea here is the same to approach 1, i.e., to find the maximum sum subarray of size ‘K + 1’, where the array will contain empty slots.
- First, we create an array na...read more
Help your peers!
Add answer anonymously...
Top Cvent Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app