Help with approach

prob: https://hack.codingblocks.com/app/practice/2/276/problem

sol: https://ide.codingblocks.com/s/419817

I have commented out the doubt

Hey it’s a dp coin change problem solution and the problem you have mentioned is find sum , confirm here.

sorry here is the code for find sum

Build balanced tree like this and after that apply your logic.


please tell why is it giving seg fault

Check now

it is giving the correct answer for the sample test case

Small errors, Have mentioned them below. Do this and all test cases will get passed

Line 27
long long int calculateSum(node* root){//updated
Line 40
long long int *arr = new long long int[n];

why did we have to initialize the array dynamically

It’s a good practice to do it. Although if you will do long long int arr[n];
Then also it will work ,but your wrong answer was because of this

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.