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

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |