Google | Phone Screen | Range Queries for Frequencies
Anonymous User
2476

Given an array of integers arr and a set of queries of the form [left, right, k], your task is to find the number of occurrences of the number k in the inclusive subarray arr[left...right] (0-based), for each query. Return the sum of the answers for all queries as the result.

Example:

Input: arr = [1, 2, 1, 3, 1, 2, 1], queries = [[1, 3, 3], [0, 4, 1], [2, 5, 2], [5, 6, 1]]
Output: 6

What was the most efficient solution for this one?

Comments (3)