Sometimes it is necessary to filter a signal by frequency, e.g. to reduce noise outside of the expected frequency range. Filters can be stacked, allowing only the frequencies within the range allowed by all filters to get through. For example, three filters with ranges of (10, 17), (13, 15) and (13, 17) will only allow signals between 13 and 15 through. The only range that all filters overlap is (13, 15). Given n
signals' frequencies and a series of m
filters that let through frequencies in the range x
to y
, inclusive, determine the number of signals that will get through the filters. There will be only one range where all the filters overlap.
Function Description
Complete the function countSignals
in the editor below.
countSignals
has the following parameter(s):
int frequencies[n]
: the frequencies of the signals sent through the filtersint filterRanges[m][2]
: the lower and upper frequency bounds for each filterReturns
int
: the number of signals that pass through all filters
Example 1:
Input: frequencies = [8, 15, 14, 16, 21], filterRanges = [[10, 17], [13, 15], [13, 17]]
Output: 2
Explanation:The range that all of the filters allow through is from 13 to 15, inclusive. The 2 frequencies that will pass through all filters have frequencies of 15 and 14. Return 2 :)
Example 2:
Input: frequencies = [20, 5, 6, 7, 12], filterRanges = [[10, 20], [5, 15], [5, 30]]
Output: 1
Explanation:The common pass-through range is 10 to 15, so only frequency 12 passes through :)
1 ≤ n ≤ 10^5
1 ≤ frequencies[i] ≤ 10^9
1 ≤ m ≤ 10^5
1 ≤ filterRanges[j][k] ≤ 10^9

input:
output: