Description
Solutions
Submission
Signal Filter 🦜
🤘 INTERN

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.

countSignals has the following parameter(s):

  1. int frequencies[n]: the frequencies of the signals sent through the filters
  2. int filterRanges[m][2]: the lower and upper frequency bounds for each filter

Returns

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.
Constraints:
    • 1 ≤ n ≤ 105
    • 1 ≤ m ≤ 105
    • 1 <= frequencies[i] <= 109
    • 1 ≤ frequencies[i], filterRanges[i][k] ≤ 109
Thumbnail 0
Testcase

Result
Case 1

input:

output: