FastPrepRange Sum Queries With Prefix Sums
Problems/Range Sum Queries With Prefix Sums

Range Sum Queries With Prefix Sums

Adobe logoAdobe● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You answer many questions of one kind: what do the values between two positions of an array add up to? An Adobe SDE intern report from an on-campus drive (May 2024, rejected) lists it as the last of three tasks in its single interview round. That round came after a CGPA cut and an online test. The report asks for running prefix sums that are then used to answer sum questions over indices. It gives no query format, limits or examples. It speaks of a subset of the indices. We read that as one unbroken range from a left index to a right index, which is what prefix sums answer.

We chose these rules. Each query is a pair [left, right] with both ends included, and indices start from 0. Answers are 64-bit integers. There are up to 10^4 values, from -10^9 to 10^9, and up to 1500 queries. We wrote new examples. At these sizes, adding each range one value at a time also passes. The editorial shows why prefix sums are faster.

Our version is about 80% the same as the reported question.

You are given an integer array nums and a list of queries. Each query [left, right] asks for the sum nums[left] + nums[left + 1] + ... + nums[right] (both ends included, indices start at 0).

Return an array whose i-th value is the answer to queries[i]. A sum can be larger than a 32-bit integer can hold, so return 64-bit integers.

Aim to build a prefix-sum array once in O(n) time and then answer each query in O(1). At these sizes the judge cannot tell this apart from adding each range one value at a time, so the goal is not checked.

Function

rangeSums(nums: int[], queries: int[][]) → long[]

Examples

Example 1

nums = [3,-1,4,-1,5]queries = [[0,2],[1,3],[4,4]]return = [6,2,5]

Indices 0 to 2 hold 3, -1 and 4, which add up to 6. Indices 1 to 3 give -1 + 4 + -1 = 2. Index 4 alone gives 5.

Example 2

nums = [1000000000,1000000000,1000000000]queries = [[0,2],[0,0]]return = [3000000000,1000000000]

The first range adds up to 3000000000, which is too big for a 32-bit integer. A 64-bit total is needed.

Example 3

nums = [-7]queries = [[0,0]]return = [-7]

A single number: the only range is index 0 to 0, and its sum is -7.

Constraints

  • 1 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • 1 <= queries.length <= 1500
  • queries[i] = [left, right] with 0 <= left <= right < nums.length

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Wallet Balance on a Selected DayBharatPe · PHONE SCREEN
  • Index With Equal Sums on Both SidesBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Parking-Lot Occupancy TimelineGoogle · PHONE SCREENGoogle interview questions
  • Calculate Server Shutdown PenaltyStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Find an Equal-Sum SplitMeta · PHONE SCREENMeta interview questions
  • Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
  • Trapping Rain WaterGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Count Non-Overlapping Pairs of Rectangles That Sum to KWisdomAI · PHONE SCREEN
  • Best Improvement Period of at Least K IntervalsAmazon · PHONE SCREEN
  • Majority Labels over Audio IntervalsNooks · PHONE SCREEN

Interview reports that mention this question

  • Adobe SWE Intern Interviews: 27 Experiences (Part 2 of 4)
  • Adobe Intern Interview Questions: 54 Experiences (Part 1 of 4)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public long[] rangeSums(int[] nums, int[][] queries) {
        // Write your code here.
    }
}
Checking account…