Computer Science, asked by kalyantony987, 3 months ago

given a 2 lane road with n positions and a total numbers of m cars moving from left to right from a strat position to a finish position determine the largest gap in postions of all cars without regard to lanes. Example n=10 start= [1,2,5,8] finish=[2,2,6,10]​

Answers

Answered by ronithomas10
1

Answer:

n = 10

start = [1,2,5,8]

finish = [2,2,6,10]

leng = list(range(1, n+1))

cars = []

empty = []

for s,f in zip(start, finish):

   for r in range(s, f+1):

       cars.append(r)

# print (cars)

for l in leng:

   if l not in cars:

       empty.append(l)

# print (empty)

gap = 1

for e in empty:

   for g in empty[1:]:

       if e+1 == g:

           gap +=1

print (gap)

Explanation:

DM me at [email protected] if you get stuck anywhere and also let me know if it works for different test cases

Thank you.

Similar questions