Sum of all sub arrays in O(n) Time | Hard

preview_player
Показать описание

Objec­tive: Given an array write an algorithm to find the sum of all the possible sub-arrays.

Example:

int [] a = {1, 2, 3};

Output: Possible subarrays –
{1}, {2}, {3}, {1, 2} , {2, 3}, {1, 2, 3}
So sum = 1+ 2+ 3 + 3 + 5 + 6 = 20

#algorithm #array #algo #interview
Рекомендации по теме
Комментарии
Автор

If we have to find the sum of each subarray, what would be the approach?

sauravchandra
join shbcf.ru