FastPrepSubarray Sum
Problems/Subarray Sum

Subarray Sum

Visa logoVisa● EasyNEW GRADOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

A subarray is a contiguous segment of an array. Given an array of n integers, determine the sum of all elements across all subarrays of that array.

Function

getSubarraySum(n: int, arr: int[]) → long

Examples

Example 1

n = 3arr = [4, 5, 6]return = 50

The subarrays are [4], [5], [6], [4, 5], [5, 6], and [4, 5, 6].

Their total sum is 4 + 5 + 6 + (4 + 5) + (5 + 6) + (4 + 5 + 6) = 50.

Example 2

n = 3arr = [1, 1, 1]return = 10

The subarrays are [1], [1], [1], [1, 1], [1, 1], and [1, 1, 1].

Their total sum is 1 + 1 + 1 + (1 + 1) + (1 + 1) + (1 + 1 + 1) = 10.

Constraints

  • 1 <= n <= 2 * 10^5
  • 1 <= arr[i] <= 10^3, where 0 <= i < n

More Visa Online Assessment questions

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Lock CodeOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
  • Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
  • Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
  • Count Valid Space-Delimited WordsOA · Seen Oct 2026
  • Earliest Common Meeting StartOA · Seen Oct 2026
  • Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
  • Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026

Similar questions at other companies

  • Next Pascal Row CoefficientIntuit · OAIntuit interview questions
  • Find Max Number of PairsRoblox · OARoblox interview questions
  • Get Triplet CountIBM · OAIBM interview questions
  • Sum of Pipeline Response TimesBloomberg LP · OABloomberg LP interview questions
  • Get Triplet CountPoint72 · OAPoint72 interview questions
  • Product of Subset MaximaArcesium · OAArcesium interview questions
  • Minimum Operations to Flip Exactly K BitsGoogle · OAGoogle interview questions
  • Find Maximum Number of Balanced CombinationsAmazon · OA
  • Counting Triplets Divisible by DAT&T · OAAT&T interview questions
  • Count Valid TeamsWells Fargo · OAWells Fargo interview questions
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public long getSubarraySum(int n, int[] arr) {
      // write your code here
    }

}
Checking account…