Find Last Element - Wrong Answer

#include
#define ll long long
using namespace std;

int find(ll *a, int n, ll key)
{
//Base case
if(n == 0)
{
return -1;
}

if(a[n-1] == key)
{
	return n-1;
}

return find(a+(n-1)-1, n-1, key);

}

int main() {
int n;
cin>>n;

ll a[n]; 

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

ll key;
cin>>key;

cout<<find(a,n,key);
return 0;

}


here is the correct solution
the question had zero based indexing while you followed a one based indexing and in some cases it was taking some garbage values due to that reason since the pointer was going out of the array’s bounds on recursive calls and returned garbage values

Resolved.
Thanks!!!