I have a vector A of size n. I have to calculate the partial sum of each element and write in matrix B [i, j].
The pseudo-code shows a solution O (n ^ 2);
For i = 1, 2, . . . , n
For j = i + 1, i + 2, . . . , n
B[i, j] <- A[i] + A[i+1] + ... + A[j];
Endfor
Endfor
Is there an O (n) or O (log n) solution? What would it be like?