 # Wrong Answer in test button but Right answer in custom test

#1

Your submission failed for the following input:

`A : [ 95 -> 84 -> 40 -> 77 -> 57 -> 35 -> 84 -> 45 -> 17 -> 3 -> 1 -> 98 -> 5 -> 38 -> 59 -> 73 -> 97 -> 46 -> 4 -> 38 -> 73 -> 27 -> 49 -> 45 -> 80 -> 99 -> 98 -> 10 -> 20 -> 46 -> 29 -> 85 -> 43 -> 13 -> 99 -> 12 -> 20 -> 71 -> 79 -> 1 -> 1 -> 57 -> 31 -> 78 -> 59 -> 16 -> 11 -> 7 ]`

Your function returned the following :

`-88 -> -73 -> -24 -> -18 -> 21 -> -4 -> -27 -> -44 -> -16 -> 76 -> 1 -> 98 -> 5 -> 38 -> 59 -> 73 -> 97 -> 46 -> 4 -> 38 -> 73 -> 27 -> 49 -> 45 -> 80 -> 99 -> 98 -> 10 -> 20 -> 46 -> 29 -> 85 -> 43 -> 13 -> 99 -> 12 -> 20 -> 71 -> 79 -> 1 -> 1 -> 57 -> 31 -> 78 -> 59 -> 16 -> 11 -> 7`

The expected returned value :

`-88 -> -73 -> -24 -> -18 -> 21 -> -4 -> -27 -> -44 -> -16 -> 76 -> 70 -> -78 -> 7 -> 61 -> -46 -> -30 -> -12 -> -17 -> 42 -> -18 -> -63 -> 71 -> 50 -> 35 -> 80 -> 99 -> 98 -> 10 -> 20 -> 46 -> 29 -> 85 -> 43 -> 13 -> 99 -> 12 -> 20 -> 71 -> 79 -> 1 -> 1 -> 57 -> 31 -> 78 -> 59 -> 16 -> 11 -> 7`

While run in custom test with same input that return this output(expected output) :
`-88 -> -73 -> -24 -> -18 -> 21 -> -4 -> -27 -> -44 -> -16 -> 76 -> 70 -> -78 -> 7 -> 61 -> -46 -> -30 -> -12 -> -17 -> 42 -> -18 -> -63 -> 71 -> 50 -> 35 -> 80 -> 99 -> 98 -> 10 -> 20 -> 46 -> 29 -> 85 -> 43 -> 13 -> 99 -> 12 -> 20 -> 71 -> 79 -> 1 -> 1 -> 57 -> 31 -> 78 -> 59 -> 16 -> 11 -> 7`

My Code :

ListNode * b;
static int k=0;
void ans(ListNode * a,int n)
{

`````` if(a->next)
ans(a->next,n);

if(k<n)
{
k++;
b->val=a->val-(b->val);
b=b->next;

}
``````

}

ListNode* Solution::subtract(ListNode* a) {
if(a==NULL || a->next==NULL)
return a;

``````int n=1;

ListNode* temp=a;

while(temp->next!=NULL)
n++,temp=temp->next;

b=a;

ans(a,n/2);

return a;
``````

}

#2