The code is running fine but only one test case is not being passed.
Here is the link of the code given below.
Doubt in Is Array Sorted?
@ratulhans
Two changes required in your code.
First of all you need to return the answer computed in recursive calls . You have not used the return statement with your recursive calls .
Change Line No. 9 from
IsArraySorted(a,n,spos+1);
to
return IsArraySorted(a,n,spos+1);
Also you shouldn’t try to access a[spos+1] if you are already at the last position of the array as this will pick some garbage value and give you a wrong answer.
Change Line No. 6 to
if(spos < n-1 && a[spos]>a[spos+1])
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.