Answer to Question #216835 in Java | JSP | JSF for harsh

Question #216835

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
Expert's answer
2021-07-14T05:50:33-0400
import java.io.*;
 
class Main {
    public static int get(int arr[], int dep[],
                                   int n)
    {
        int p= 1, rlt = 1;
        int i = 1, j = 0;
        for (i = 0; i < n; i++) {
            p = 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]))
                    p++;
            }
            rlt = Math.max(rlt, p);
        }
 
        return rlt;
    }
    public static void main(String[] args)
    {
        int arr[] = {1800, 950, 940, 900, 1500,1800 };
        int dep[] = { 1200, 1120,910,2000,1900,2000 };
        int n = 6;
        System.out.println(get(arr, dep, n));
    }
}

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