Comments on: Add sum of all previous elements in array (DPFCI_1.2) https://demo.ritambhara.in/add-sum-of-all-previous-elements-in-array/ Coding / System Design Interviews Thu, 25 May 2017 16:40:17 +0000 hourly 1 https://wordpress.org/?v=6.9 By: Gaurav Joshi https://demo.ritambhara.in/add-sum-of-all-previous-elements-in-array/#comment-2033 Thu, 25 May 2017 16:40:17 +0000 http://www.ritambhara.in/?p=8179#comment-2033 In reply to Gaurav Joshi.

It should be some thing like this:
Called something like this:
SumArray(arr,0,n,sum)
SumArray(arr,i,n,sum)
{
if(i==n) return;
arr[i]= arr[i]+sum;
SumArray (arr,i+1, n, arr[i]);
}

]]>
By: Gaurav Joshi https://demo.ritambhara.in/add-sum-of-all-previous-elements-in-array/#comment-2032 Thu, 25 May 2017 16:25:15 +0000 http://www.ritambhara.in/?p=8179#comment-2032 Your tail recursion looks incorrect. You have only updated arr[0] where are rest indices updated.

]]>