I cant understand how the program is working even after unlocking the editorial.
How to make recursive function for R9-- Found At last
hi shivesh
as u find the index from first
i.e
if(arr[i]== target)return i; and then recursive call
in this the call stack will be formed like
eg 1 3 2 5 2 7 2 8
so first check for 1 then 3 and when 2 comes above condition satisfy therefor it return i=2
so when u find the last index u have to check from last so u have to put all index in the recursive stack and then check index from moving backward
i.e recursive call(a,i+1)
if(arr[i]==target)return i
int the call stack form
1 3 2 5 2 7 2 8
and now all element are in stack and now u r checking first element 8 is check then 2 is check and it is satisfiesd hecnce i=6 return
just mske the call stack according to code