void recursion(struct TreeNode* root,int sum,int* returnSize,int* returnColumnSizes,int**arr,int* temp,int cnt,int* total){ if(!root) return; *(total)+=root->val; temp[cnt]=root->val; if(!root->left && !root->right && *total == sum){ arr[(*returnSize)]=(int*)calloc(1000,sizeof(int)); memcpy(arr[(*returnSize)],temp,(cnt+1)*sizeof(int)); returnColumnSizes[(*returnSize)++]=cnt+1; } recursion(root->left,sum,returnSize,returnColumnSizes,arr,temp,cnt+1,total); recursion(root->right,sum,returnSize,returnColumnSizes,arr,temp,cnt+1,total); *(total)-=root->val; } int** pathSum(struct TreeNode* root, int sum, int* returnSize, int** returnColumnSizes){ int** arr=(int**)calloc(1000,sizeof(int*)); *returnColumnSizes=(int*)calloc(1000,sizeof(int)); *returnSize=0; int total=0; int temp[1000]; recursion(root,sum,returnSize,*returnColumnSizes,arr,temp,0,&total); return arr; }