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;
}