Problem in code


it passes in two cases , but failed in one case,
so please point out error

Hi @mkjha,
In ur code, if n-1==0, u r returning -1 from the function. So if n=1, the function will return -1 which is not true for all cases.
for eg. if n=1 and arr={1} and u need to find last index of 1.
Here the output should be 1 but ur code will print -1 as output.
Add dis edge case. Rest of ur code is fine.
Hope dis resolves ur doubt.

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.