Top Coding Interview Question – Solved

8 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

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |