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.
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));
}
}
Comments
Leave a comment