Frequency Between Range
MediumP3Coding
You are given an array nums and a list of queries. Each query is [left, right, value]. For each query, count how many elements equal to value lie at positions left to right, inclusive. Positions are 1-based.
Return the answers in the order of the queries.
Example 1
- Input
- nums = [1,2,1,3,1], queries = [[1,5,1],[2,4,1],[1,2,2]]
- Output
- [3,1,1]
Example 2
- Input
- nums = [5], queries = [[1,1,5],[1,1,4]]
- Output
- [1,0]
Example 3
- Input
- nums = [2,2,2,2], queries = [[1,4,2],[2,3,2],[4,4,2]]
- Output
- [4,2,1]
Constraints
- 1 <= nums.length <= 10^5
- 1 <= queries.length <= 10^5
- 1 <= left <= right <= nums.length
- -10^9 <= nums[i], value <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.