🎁 Exclusive Offer! Join our
Telegram Channel
to get **special discounts** and updates! 🚀
Question 11 - 100% Working Solution | Buy Now
Description
12 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