Semester Breaks
https://www.hackerrank.com/contests/codenection-2021-open-category-preliminary/challenges/semester-breaks
Question
Semester breaks are here so all the students are living. Since there's no good way of students to travel from Cyberjaya to Putrajaya, MMU decided to provide buses to transport the students. There are N students at the hostel each leaving their room for the bus station at time ,where is the time i-th student leaves their room. MMU has B buses each of which bus can hold up to M students in it. Kyle was assigned as a volunteer to properly assign each student to a bus in which they can travel in. The bus can leave only when the last student assigned to the bus leaves their room and goes to the station. Kyle wants to minimize the waiting time for each student. What is the smallest possible value of the largest wait time for an student?
Input Format
The first line contains three space separated integers N, B, and M. Next line contains N integers which describe the time when the students left their hostel room.
Constraints
It is guaranteed that there's always enough bus and space for all students to be transported.
Output Format
Output one integer which is the minimum possible maximum wait time for a student.
Sample Inputs:
Input
6 3 2
1 1 10 14 4 3
Output
4
Explanation
There are 6 students, 3 buses and each bus can hold upto 2 students in itself. So we put students with time 1 in first bus. Students with time 3 and 4 in second bus. Students with time 10 and 14 in the last bus. Here student who arrives at time 10 needs to wait until student with time 14 arrives. So, the answer is 4.
Note: The wait time is calculated as follows:
Where is the time when their bus leaves.
Last updated