why isnt this code giving correct answer
LastIndex
#include using namespace std; int firstIndex(int *arr,int n,int m){ if(n==0) return -1; int smallAns=firstIndex(arr+1,n-1,m); if(smallAns==-1 && arr[0]==m)return 0; else return smallAns+1; } int main() { int n; cin>>n; int arr[n]; for(int i=0;i<n;i++){ cin>>arr[i]; } int m; cin>>m; cout<<firstIndex(arr,n,m); return 0; }
updated