Answer to Question #230463 in C for aman

Question #230463

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.

  1. Devise an algorithm to find him the shuttle with the least waiting time. (waiting time = boardingj - t , where j is the next shuttle. And boardingj >= t ) for each ti
  2. If he also has access to the travel time of each shuttle. Can you help him find the shuttle which will help him reach his destination at the earliest ?

Return an array of shuttle indexes that Rahul took for n days.



1
Expert's answer
2021-08-29T00:58:23-0400
#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;
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS