Points within an interval

Question

Suppose you are given P, which is list of j integer intervals, where j is the number of intervals. The intervals are in a format [a, b].

Given an integer z, can you return the number of overlapping intervals for point z?

For example:

#Input:
P =  [[0, 2], [3, 7], [4, 6], [7, 8], [1 ,5]]
z = 5
#Output:
# 3
# At z = 5, there are 3 intervals that overlap. The intervals are: [3, 7], [4, 6], and [1, 5]

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now