Saturday, February 16, 2013

Amazon question - Schedule a meeting based on given work timings

Consider the following input and output . In the input, first line contains number of input 5 and the time you need to schedule (120 minutes) . Next five lines contains the work timings of that person , so he is busy at these times . And the output shows the list of available timings. This question is asked by amazon in interviewstreet.com . First the timings are sorted using bubble sort based on start time .And you need to compare timings to get the available timings .

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

Code: (in JAVA)

Please let me know if you have any questions .

2 comments:

Unknown said...
This comment has been removed by the author.
Unknown said...

Hi,

I tired this problem using C++

My Alogirthm is:

1) Sort the array by start time
2) calculating difference between Start time and End time of Alternate schedules.

##Note## this program passed First 7 test cases.

Can you please assist me where i did mistake..Which one i forgot to check.?

Here's my code.

#include
#include
#include
#include

using namespace std;

class meeting_Shld
{
vector slot;
int M,K,val,T,Time_sec,Start_HH=0,Start_MM=0,End_HH=24,End_MM=0;
void getData()
{
cin>>M>>K;
T=M*4;
// cout<>val;
slot.push_back(val);
}

}

void swapp(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
//cout<< """ """<<*b<<" "<<*a<<" "<slot[j])
{
swapp(&slot[i],&slot[j]);
swapp(&slot[i+1],&slot[j+1]);
swapp(&slot[i+2],&slot[j+2]);
swapp(&slot[i+3],&slot[j+3]);


}
else if(slot[i]==slot[j])
{
if(slot[i+1]>slot[j+1])
{
swapp(&slot[i],&slot[j]);
swapp(&slot[i+1],&slot[j+1]);
swapp(&slot[i+2],&slot[j+2]);
swapp(&slot[i+3],&slot[j+3]);

}
}


}




}
void display()
{
for(int i=0,j=1;i=0)
{
Time_sec=Time_sec+(slot[1]-Start_MM);
//cout<=K)
cout<=0)
{
Time_sec=Time_sec+(slot[i+3]-slot[i+1]);
if(Time_sec>=K)
cout<=0)
{

Time_sec=Time_sec+(End_MM-slot[T-1]);
//cout<=K)
cout<<setw(2)<<setfill('0')<<slot[T-2]<<" "<<setw(2)<<setfill('0')<<slot[T-1]<<" "<<setw(2)<<setfill('0')<<End_HH-24<<" "<<setw(2)<<setfill('0')<<End_MM<<endl;


}

}


//-----------------------------End of day --------------------------------------------------------------------------------------------------------------



}

public:

void get_start()
{
getData();
sortData();
//display();
//cout<<endl;
getMeeting();



}



};


int main()
{
meeting_Shld ms;
ms.get_start();
return 0;
}