Top Coding Interview Question – Solved

2 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

| The supply chain manager at one of Amazon's warehouses is shipping the last con… |
| Determine the highest value after executing n steps on an infinite 2D grid that… |
| Amazon Prime Video is developing a new feature called "Segmentify." This featur… |
| In this new stock prediction game launched on Amazon Games, Player 1 provides P… |
| Amazon operates numerous warehouses, with each warehouse holding inventory[i] u… |
| In Amazon's highly efficient logistics network, minimizing operational overhead… |