Skip to content
Onsite

Count Numbers in Range Queries

MediumP3Coding

Given an array nums and a list of queries, where each query is [l, r], return for each query how many elements of nums have a value v with l <= v <= r. The array is not sorted and l <= r always holds.

Answer the queries in the same order they were given.

Example 1

Input
nums = [5,1,9,3,3], queries = [[1,3],[4,8],[10,20]]
Output
[3,1,0]

Example 2

Input
nums = [2,2,2], queries = [[2,2]]
Output
[3]

Example 3

Input
nums = [], queries = [[0,5]]
Output
[0]

Constraints

  • 0 <= nums.length <= 10^5
  • 1 <= queries.length <= 10^5
  • -10^9 <= nums[i], l, r <= 10^9

Hints

Run checks the 3 visible tests, Submit all 9.