Arrivals and departures are "events", and your arrays contain the times of those events. The basic logic is to find the time of the next event and do the updates associated with that event. For arrivals, queue length is incremented. For departures, the queue length is decremented. The following is a rather brute-force implementation (Python3 since you didn't specify) of that idea which prints out the time and the queue length whenever it changes:
a = [1.1, 2.9, 5.1, 6.5]
d = [3.5, 5.2, 7.2, 8.0]
queue = 0
a_index = 0
d_index = 0
print(0, ':', queue)
while a_index < len(a) and d_index < len(d):
if a[a_index] < d[d_index]: # did an arrival come first?
queue += 1
print(a[a_index], ':', queue)
a_index += 1
else:
queue -= 1
print(d[d_index], ':', queue)
d_index += 1
# ran out of elements in one of the arrays,
# iterate through remainder of the other
while a_index < len(a):
queue += 1
print(a[a_index], ':', queue)
a_index += 1
while d_index < len(d):
queue -= 1
print(d[d_index], ':', queue)
d_index += 1
If you want to print only at integer times, set those up as events as well:
a = [1.1, 2.9, 5.1, 6.5]
d = [3.5, 5.2, 7.2, 8.0]
queue = 0
a_index = 0
d_index = 0
print_time = 1
max_time = 10
print(0, ':', queue)
while a_index < len(a) and d_index < len(d):
if a[a_index] < d[d_index] and a[a_index] <= print_time:
queue += 1
a_index += 1
elif d[d_index] <= print_time:
queue -= 1
d_index += 1
else:
print(print_time, ':', queue)
print_time += 1
while a_index < len(a):
if a[a_index] <= print_time:
queue += 1
a_index += 1
else:
print(print_time, ':', queue)
print_time += 1
while d_index < len(d):
if d[d_index] <= print_time:
queue -= 1
d_index += 1
else:
print(print_time, ':', queue)
print_time += 1
while print_time <= max_time:
print(print_time, ':', queue)
print_time += 1
These could undoubtedly be tightened up, but they convey the approach.
If you had more than this small number of events, a better organizing principle would be to place the events in a priority queue, ordered by time of occurrence, then pull them off one-by-one and dispatch to the appropriate state transition logic based on which event type occurred. You can find the logic of this approach described in this paper. The paper implements the ideas in Java, but a Python3 implementation and a demo queueing model are available here.