Can you please explain the use of this statement properly like a dry run as i’m not able to get when the recursive calls are happening exactly.
"int rr= lastIndex( arr, n, key, idx+1); "
#include
using namespace std;
int lastIndex( int arr[], int n,int key, int idx)
{
//base case
if(idx == n)
return -1;
int rr= lastIndex( arr, n, key, idx+1);
//rec case
if(key== arr[idx] && rr == (-1))
{
return idx;
}
return rr;
}
int main()
{
int n;
cin>>n;
int a[1000];
for( int i=0; i<n; i++)
cin>>a[i];
int key;
cin>>key;
cout<<lastIndex(a, n, key, 0);
return 0;
}