Lunatic Server Solutions Interview Question
Developer Program EngineersCountry: United States
Interview Type: Written Test
If the service time is 3 min per customer, then for the input
9 0 2 5 6 6 8 10 -1
the output should be:
3 6 6 8
Why your output is 2 6 8?
statement
is very clear and does not
generate any ambiguity. "If
counter is expected to be vacant
at time 't', the first person in the
queue will be scheduled for the
service". This means that the
queue status is to be printed
after the next person gets the
service. If two persons arrive at
same time, one of them will get
service when the current person
is done with. The second person
will get service after further 3
minutes. The sample input is
explained here.
Here, persons are identified by
their arrival time.
Time Queue comment
0 0
1 0
2 0 2 2 arrives
3 2 t=3, 0 is done 2 gets
service
4 2
5 2 5 5 arrives
6 5 2 over 5 gets service, 6
and 6 arrives
7 5 6 6 still waiting
8 5 6 6 still waiting, 8 8
arrives
9 6 6 gets service, 6 and 8
in the queue
output must be 2 6 8
int total_wait=0;
because it ask for waiting people
on t = 2 , 1 person and get service up to t=5 and not waiting,
on t=5, 1 person come and get service up to t=8 and not waiting,
on t=6, 1 person came and waiting up to t=8,
total_wait = total_wait+1; // = 1
on t=8, this person get services before N=9, so this is not waiting,
total_wait = total_wait-1; // = 0
on t=6, 1 more person came and waiting up to t=(8+3) = 11 and this is more than N=9 so it is waiting,
total_wait = total_wait+1; // = 1
on t=8, i person came and waiting up to t=(11+3)=15
and this is more than N=9 so it is waiting,
total_wait = total_wait+1; // = 2
so total_wait person = 2 and their arrival 6 8
if you got it e-mail me harindra.it@gmail.com
Int checkpointTime = 9; //Read it from Console
Queue q = new Queue(); // Populate queue from Console
Int serviceTimePerCustomer = 3;
Int currentTime = 0;
While(!q.IsEmpty())
{
If(checkpointTime == 0)
{
// checkpoint time reached. Queue is not empty
// Dequeue the head and be done
q.Dequeue();
break;
}
If(checkpointTime < 0)
Break;
Int arrivalTime = q.Dequeue();
If(currentTime >= arrivalTime)
{
currentTime += serviceTimePerCustomer;
}
Else
{
currentTime = arrivalTime + serviceTimePerCustomer;
}
checkpointTime -= currentTime;
}
Print q.Count; foreach(int num in q) print num;
output must be 2 6 8 because it ask for waiting people
int total_wait=0;
on t = 2 , 1 person and get service up to t=5 and not waiting,
on t=5, 1 person come and get service up to t=8 and not waiting,
on t=6, 1 person came and waiting up to t=8,
total_wait = total_wait+1; // = 1
on t=8, this person get services before N=9, so this is not waiting,
total_wait = total_wait-1; // = 0
on t=6, 1 more person came and waiting up to t=(8+3) = 11 and this is more than N=9 so it is waiting,
total_wait = total_wait+1; // = 1
on t=8, i person came and waiting up to t=(11+3)=15
and this is more than N=9 so it is waiting,
total_wait = total_wait+1; // = 2
so total_wait person = 2 and their arrival 6 8
if you got it e-mail me harindra.it@gmail.com
#include<stdio.h>
int main(){
int time = -1,ar=0,te=0;
int n,i=0,f, queue[100];
while(1){
scanf("%d",&n);
if(n == -1)
break;
if(time == -1){
time = n;
}
else{
if(n <= time){
if(te <= time){
if(te < n)
te = n;
}
else{
queue[i++] = n;
}
te = te+3;
}
}
}
printf("%d",i);
for(f=0;f<i;f++){
printf(" %d",queue[f]);
}
return 0;
}
so what is t supposed to be in your input/output? i dont really understand your example
- Anonymous May 23, 2012