Question: Gaps in Traffic STDIN Function 1 0 } - > n = 1 start [ ] size m = 2 start = [ 3

Gaps in Traffic STDIN Function
10}->n=1
\ start[] size m =2
start =[3,8]
-> finish[] size m=2
\ finish =[4,9]
Sample Output 0
3
Explanation 0
n=10, start =[3,8], finish =[4,9]
The diagram above depicts a road n=10 units in length with m=2 cars :
The first car spans from position start[0]=3 to position finish[0]=4
The second car spans from position start[1]=8 to position finish[1]=9
No car is in positions [1,2], positions [5,6,7] or position [10]. The largest gap between cars
is 3. Language
Python 3
The diagram above depicts a road n=10 units in length with m=4 cars :
The first car spans from position start[0]=1 to position finish [0]=2
The second car spans from position start [1]=2 to position finish [1]=2
The third car spans from position start[2]=5 to position finish[2]=6
The fourth car spans from position start[3]=8 to position finish[3]=10
There are gaps at positions 3-4 and 7. The largest gap between cars is 2.
Autocomplete Read
15 # 1. INT
16 # 2. IN
1n109
1m105
1 start [i] finish [i]n, where 0i.
Given a 2 lane road with n positions and a total number of m cars moving from left to
right, from a start position to a finish position, determine the largest gap in positions of all
cars, without regard to lanes.
Example
n=10
start =[1,2,5,8]
finish =[2,2,6,10]
The following is a graphical representation of a snapshot of the cars on the road. start and
finish mark the positions of the rear and front of each car. The length of the road is n.
n=10, start =[1,2,5,8], finish =[2,2,6,10]
Positions that contain cars are gray, and positions that are open are striped green.
The diagram above depicts a road n=10 units in length with m=4 cars :
Gaps in Traffic STDIN Function 1 0 } - > n = 1 \

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!