What is the bug in this I treid submitting but it is showing wrong answer

include
using namespace std;

int arr[1001];

int RobKnapsack(int N)
{

if(N == 0)
	return 0;

if(N == 1)
	return arr[0];

int rob[N];
rob[0] = arr[0];
rob[1] = max(rob[0], arr[1]);
if(N == 2)
	return rob[1];
for(int i=2; i<N; i++)
	rob[i] = max(arr[i]+rob[i-2], rob[i-1]);	
return rob[N-1];

}

int main() {

int N, ans;
cin>>N;
for(int i=0; i<N; i++)
	cin>>arr[i];
ans = RobKnapsack(N);
cout<<ans;
return 0;

}

Hey Satyam!, Your logic is fine and works perfect (got ACCEPTED Leetcode as well), just see the array size.
Also you need to answer for multiple testcases which you forgot to do!


see it works fine now!

Yes it works now. Thanks

Np mark doubt as resolved if satisfied!