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

Опубликовано: 28 Февраль 2024
на канале: Tutorial Horizon
567
8

Complete Post: https://tutorialhorizon.com/algorithm...

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