FastPrepAdvertisement Click Range Sums
Problems/Advertisement Click Range Sums

Advertisement Click Range Sums

Google logoGoogle● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the goal of range queries on a click log, the prefix-sum direction, and follow-ups on point updates and memory. It does not give the function signature, how queries are indexed, or number limits. Our version is about 92% the same as the reported question.

You are given an integer array clicks, where clicks[i] is the number of advertisement clicks recorded in time bucket i, and an array queries of range queries.

Each query is a two-element array [left, right] describing a zero-based, inclusive range. Return a long[] whose value at index j is the total number of clicks from queries[j][0] through queries[j][1]. Preserve the input query order.

Interview extensions

  • Explain how the design would change if the click array supported point updates between range-sum queries.
  • Explain how a streaming consumer could process millions of queries without retaining the entire query batch or answer batch in memory.

Function

rangeClickSums(clicks: int[], queries: int[][]) → long[]

Examples

Example 1

clicks = [3,0,2,5,1]queries = [[0,2],[1,3],[3,4]]return = [5,7,6]

The three inclusive totals are 3 + 0 + 2 = 5, 0 + 2 + 5 = 7, and 5 + 1 = 6.

Example 2

clicks = [4]queries = [[0,0]]return = [4]

The only query covers the single time bucket, so its total is 4.

Example 3

clicks = [0,0,0]queries = [[0,2],[1,1]]return = [0,0]

Every bucket contains zero clicks, so every queried total is 0.

Example 4

clicks = [1000000000,1000000000,1000000000]queries = [[0,2],[1,2]]return = [3000000000,2000000000]

The totals exceed the int range, so they are returned as long values.

Constraints

  • 1 <= clicks.length <= 200000
  • 0 <= clicks[i] <= 10^9
  • 1 <= queries.length <= 200000
  • Each queries[j] contains exactly two integers [left, right].
  • 0 <= left <= right < clicks.length
  • Range totals may exceed the int range, so return them as long values.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Roll a Weighted DieLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Calculate Server Shutdown PenaltyStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Leftmost Equilibrium IndexExpedia · ONSITE INTERVIEWExpedia interview questions
  • Find Pivot IndexMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Shortest Subarray with Sum at Least KOracle · ONSITE INTERVIEWOracle interview questions
  • Subarray Sum Equals KServiceNow · ONSITE INTERVIEWServiceNow interview questions
  • Product of Array Except SelfWalmart Labs · ONSITE INTERVIEW
  • Subarrays Whose Sum Is a Power of TwoKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Maximize Compatible Car RidersUber Freight · PHONE SCREEN · ONSITE INTERVIEWUber Freight interview questions
  • Count Subarrays with Sum KMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public long[] rangeClickSums(int[] clicks, int[][] queries) {
      // Write your code here.
    }

}
Checking account…