FastPrepSum an Arbitrary-Dimensional Array
Problems/Sum an Arbitrary-Dimensional Array

Sum an Arbitrary-Dimensional Array

LinkedIn logoLinkedIn● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report identifies summing an arbitrary-dimensional array through dimension and indexed-value access. The finite row-major adapter preserves that capability.

An arbitrary-dimensional integer array exposes its positive dimensions and stores its entries in row-major order in values, with the last dimension varying fastest.

Return the signed 64-bit sum of all entries. The product of the dimensions equals values.length.

Function

sumMultidimensionalArray(dimensions: int[], values: int[]) → long

Examples

Example 1

dimensions = [2,2,2]values = [1,2,3,4,5,6,7,8]return = 36

The eight entries of the 2 by 2 by 2 array sum to 36.

Example 2

dimensions = [3]values = [-5,2,9]return = 6

A one-dimensional array follows the same contract.

Constraints

  • 1 <= dimensions.length <= 12
  • 1 <= dimensions[i]
  • 1 <= values.length <= 200000
  • The dimension product equals values.length.
  • Each value fits in a signed 32-bit integer; the sum fits in a signed 64-bit integer.

More LinkedIn problems

  • Total Years of Work ExperiencePHONE SCREEN · Seen Nov 2026
  • Explore an Unknown Grid and Find a PathONSITE INTERVIEW · Seen Nov 2026
  • Fire Station Response BillONSITE INTERVIEW · Seen Nov 2026
All LinkedIn interview questionsSee LinkedIn hiring insights
Saved
class Solution {
    public long sumMultidimensionalArray(int[] dimensions, int[] values) {
        // Write your code here.
    }
}
Checking account…