algorithms.tutorialhorizon.com
Sum of all sub arrays in O(n) Time | Algorithms
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