Loading...
You are given a list of closed integer intervals intervals, where intervals[i] = [start_i, end_i] represents the interval [starti,endi] (both ends inclusive). You are also given an integer array queries, where queries[j] is a query point.
For each query point, count how many intervals contain it. An interval [starti,endi] contains a point p when starti≤p≤endi.
Return an integer array answer of the same length as queries, where answer[j] is the number of intervals that contain queries[j].
Input: intervals = [[1,6],[3,7],[9,12],[4,13]], queries = [2,3,7,11]
Output: [1,2,2,2]
Explanation:
- Point 2 lies in [1,6] only, so the count is 1.
- Point 3 lies in [1,6] and [3,7], so the count is 2.
- Point 7 lies in [3,7] and [4,13], so the count is 2.
- Point 11 lies in [9,12] and [4,13], so the count is 2.
Input: intervals = [[1,10],[3,3]], queries = [3,3,2]
Output: [2,2,1]
Explanation:
- Point 3 lies in [1,10] and [3,3], so the count is 2.
- Point 3 again lies in both intervals, so the count is 2.
- Point 2 lies in [1,10] only, so the count is 1.
intervals.length ≤5×104intervals[i].length ==2queries.length ≤5×104queries[j] ≤109Click "Run" to test with sample cases or "Submit" to run all tests.