Here is the Amazon coding challenge with solution. Please do comment below if you find any issues with the solution. Ready to learn and evolve. Knowledge is Power.

Given M busy-time slots of the team members in the Kindle team, can you print all the available time slots when all of them can schedule a meeting for a duration of K minutes.

The event time will be of the form HH MM (where 0 <= HH <= 23 and 0 <= MM <= 59). K will be in the form minutes.

Input Format:

M K [M number of busy time slots , K is the duration in minutes]

This is followed by M lines with 4 numbers on each line.

Each line will be of the form StartHH StartMM EndHH EndMM [Eg: 9am-11am time slot will be given as 9 00 11 00]

An event time slot is of the form [Start Time, End Time) which means the start time is inclusive but not the end time;

So, an event of the form 10 00 11 00 => implies that the meeting starts at 10:00 and ends at 11:00. Hence, another meeting can start at 11:00.

Sample Input:

5 120

16 00 17 00

10 30 14 30

20 45 22 15

10 00 13 15

09 00 11 00

Sample Output:

00 00 09 00

17 00 20 45

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

#include

#include

using namespace std;

int main()

{

int bTimeSlots, duraInMin;

cin >> bTimeSlots >> duraInMin;

int startHH, stopHH, startMM, stopMM;

const int minPerday = 1440;

int storeBooking[minPerday] = {0};

for (int i=0;i cin >> startHH >> startMM >> stopHH >> stopMM;

if (startHH>24 or stopHH > 24 or startMM > 59 or stopMM>59)

exit(EXIT_FAILURE);

int startMeet = startHH * 60 + startMM;

int stopMeet = stopHH * 60 + stopMM;

for (int j=startMeet;j<=stopMeet;j++){

storeBooking[j]=1;

}

}

int timeInterval = 0;

int freeTimeStart=0, freeTimeStop;

for (int k=0;k

if (storeBooking[k]==1){

if ((k/duraInMin) > 0 && storeBooking[k-1]==0){

if ((k - freeTimeStart) >= duraInMin){

cout << setfill('0') << setw(2) << freeTimeStart/60

<< " "

<< setfill('0') << setw(2) << freeTimeStart%60

<< " "

<< setfill('0') << setw(2) << k/60

<< " "

<< setfill('0') << setw(2) << k%60

<< "\n";

}

}

freeTimeStart = k;

}else if(k==minPerday -1){

if ((k - freeTimeStart) >= duraInMin){

int finalHH;

if (((k+1)/60)==24){ finalHH=0; }else{finalHH = (k+1)/60; }

cout << setfill('0') << setw(2) << freeTimeStart/60

<< " "

<< setfill('0') << setw(2) << freeTimeStart%60

<< " "

<< setfill('0') << setw(2) << finalHH

<< " "

<< setfill('0') << setw(2) << (k+1)%60

<< "\n";

}

}

}

}

Given M busy-time slots of the team members in the Kindle team, can you print all the available time slots when all of them can schedule a meeting for a duration of K minutes.

The event time will be of the form HH MM (where 0 <= HH <= 23 and 0 <= MM <= 59). K will be in the form minutes.

Input Format:

M K [M number of busy time slots , K is the duration in minutes]

This is followed by M lines with 4 numbers on each line.

Each line will be of the form StartHH StartMM EndHH EndMM [Eg: 9am-11am time slot will be given as 9 00 11 00]

An event time slot is of the form [Start Time, End Time) which means the start time is inclusive but not the end time;

So, an event of the form 10 00 11 00 => implies that the meeting starts at 10:00 and ends at 11:00. Hence, another meeting can start at 11:00.

Sample Input:

5 120

16 00 17 00

10 30 14 30

20 45 22 15

10 00 13 15

09 00 11 00

Sample Output:

00 00 09 00

17 00 20 45

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

#include

#include

using namespace std;

int main()

{

int bTimeSlots, duraInMin;

cin >> bTimeSlots >> duraInMin;

int startHH, stopHH, startMM, stopMM;

const int minPerday = 1440;

int storeBooking[minPerday] = {0};

for (int i=0;i

if (startHH>24 or stopHH > 24 or startMM > 59 or stopMM>59)

exit(EXIT_FAILURE);

int startMeet = startHH * 60 + startMM;

int stopMeet = stopHH * 60 + stopMM;

for (int j=startMeet;j<=stopMeet;j++){

storeBooking[j]=1;

}

}

int timeInterval = 0;

int freeTimeStart=0, freeTimeStop;

for (int k=0;k

if (storeBooking[k]==1){

if ((k/duraInMin) > 0 && storeBooking[k-1]==0){

if ((k - freeTimeStart) >= duraInMin){

cout << setfill('0') << setw(2) << freeTimeStart/60

<< " "

<< setfill('0') << setw(2) << freeTimeStart%60

<< " "

<< setfill('0') << setw(2) << k/60

<< " "

<< setfill('0') << setw(2) << k%60

<< "\n";

}

}

freeTimeStart = k;

}else if(k==minPerday -1){

if ((k - freeTimeStart) >= duraInMin){

int finalHH;

if (((k+1)/60)==24){ finalHH=0; }else{finalHH = (k+1)/60; }

cout << setfill('0') << setw(2) << freeTimeStart/60

<< " "

<< setfill('0') << setw(2) << freeTimeStart%60

<< " "

<< setfill('0') << setw(2) << finalHH

<< " "

<< setfill('0') << setw(2) << (k+1)%60

<< "\n";

}

}

}

}