Si value in the function call: lastIndex(arr, si +1,data)

what is the use of doing si+1 in the call of the function: lastIndex( arr , si+1 , data)

we can directly use:
if(si == arr.length)

@HimanshuSingh8998,

si+1 is basically when we are calling the function again with index incremented by 1. It will start returning values when we hit our base case.

It is checking index si = 0 but before checking the index si=0 it checks the next index si =1 and so on till last index and when the recursion call ends it returns the index and if the index !=-1 and the element is found then it returns si.

@HimanshuSingh8998,

Solution algorithm is : For finding last index of element in increasing stack of recursion you have to add one more variable in function i.e. ans, and initially you pass ans = -1. While give recursive call if you find the element at that index reinitialize ans with that index and make recursive call with new ans and si + 1. At base condition I.e. si == end, you will simply just return the ans.

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.