Rahul lives in City A and would like to travel to City B for work. There is a shuttle service for people in these cities which has a fixed schedule. The schedule for City A is a list of boarding times(at City A) and departure times(from City A) for each bus.
Note: No one is allowed to board a shuttle after the boarding time.
He arrives at time t and sometimes has to wait at the station. You are given a list of arrival times for n days.
Return an array of shuttle indexes that Rahul took for n days.
#include <stdio.h>
#include <math.h>
int least(int arr[], int dep[],int n)
{
int q= 1;
int i = 1, j = 0;
for (i = 0; i < n; i++) {
q = 1;
for (j = i + 1; j < n; j++) {
if ((arr[i] >= arr[j] && arr[i] <= dep[j])
|| (arr[j] >= arr[i]
&& arr[j] <= dep[i]))
q++;
}
}
return least;
}
int main(){
int i=1;
int j=0;
int arr[] = {1500, 650, 440, 400, 2500,800 };
int dep[] = {200, 120,510,1500,1900,2200 };
int n = 4;
printf("shuttle with least waiting time is shuttle number 4%c\n");
int arri[6] ={0,1,2,3,4,5};
return arri;
}
Comments
Leave a comment