Q ->last index mi code is not pass the 1 test case

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int last_index(ll a[],ll n,ll key)
{
if(n==0)
{
return -1;
}
if(a[n-1]==key)
{
return 0;
}
ll i=last_index(a,n-1,key);

return i+1;

}
int main()
{
// let’s play
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
ll a[n];
for(ll i=0;i<n;i++)
cin>> a[i];
ll key;
cin>>key;
int last=last_index(a,n,key);
cout<<n-1-last<<endl;
return 0;
}

Save your code on ide.codingblocks.com and then share its link.

https://ide.codingblocks.com/s/291103

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.