isSorted Array through Recursion

Does my code algorithm looks good ? It is different from solution provided. Do you think it will fail in any condition.

Test Condition:

int[] array = {1,2,4,4,4,5,7};

System.out.println(“Result isSorted=” + isSorted(array,array.length-1));

Code:

public static boolean isSorted ( int[] array, int si ) {

	if( si == 0 ) return true;
	boolean result = (array[si] >= array[si-1]) && isSorted(array,si-1);
	return result;

}

Hey @connectrajanjain Your code looks fine and it will not fail for any testcase.

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.

Please see image for test case for which it is failing.