Regarding smart robber question in algorithm section

//1 test case failing
please help!

int a[1000000];
int dp[1000000];
int n,i;

int solve(int idx){

if(idx>=n){
	return 0;
}

if(dp[idx]!=0){
	return dp[idx];
}


int sum1 = a[idx] + solve(idx+2);
int sum2 = solve(idx+1);

dp[idx] = max(sum1,sum2);

return max(sum1,sum2);

}

int main() {

int t;
cin>>t;
while(t--){

	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}

	cout<<solve(0)<<endl;
	memset(a,0,sizeof(a));
	memset(dp,0,sizeof(dp));
}
return 0;

}

Hey @talhashamim001
Your logic looks good
Try using long long and also pass array and n locally instead of making them globally.That might be causing some issue

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.