Top Coding Interview Question – Solved

10 Live
A subarray is any contiguous block of an array's elements. Given an array of integers, find the sum of all elements of all subarrays of that array. Example For example, a three element array [4, 5, 6] can be made into the following subarrays: 1 element subarrays: [4], [5], [6] 2 element subarrays: [4,5], [5,6] 3 element subarrays: [4, 5, 6] The sum of all subarrays is 4 + 5 + 6 + (4+5) + (5+6) +(4+5+6)=50. Function Description subarraySum has the following parameter(s): int arr[n]: an array of integers to process Returns: int: an integer representing the sum of all subarrays of the given array Constraints - 1 <= n <= 2Γ— 105 - 1<=arr[i] ≀ 10^3, where 0 ≀ 7< n

Asked in: No companies listed

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| As an operations engineer at Amazon, you are responsible for organizing the dis… |
| Amazon Books is a retail store that sells the newly launched novel "The Story o… |
| In an Amazon analytics team, the Analysts collectively have a preference for th… |
| AWS provides scalable systems. A set of n servers are used for horizontally sca… |
| A foundry in Hackerland makes an alloy out of n different metals. In the manufa… |
| An array of integers is almost sorted if at most one element can be deleted fro… |