Last occurrence?

how will we last from last using recursion ? in the last occurrence recursion

Here’s the algorithm for that:-

Step 1: To solve this using recursion, make a recursion function with inputs, and a variable currIndex to traverse the input array.

Step2: Base Case:- If currIndex == size of the input array, return -1, i.e element not found.

Step3: Take input of next recursion call ,withcurrIndex incremented by 1 , in a variable ‘index’.

Step 4:
If(index == -1 && input[currIndex] == x)
Return currIndex
Else
Return index;

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.