Sorted Array | Test Case Failing

My code is failing the Test Case 1. I do not know what is that test case. But I have checked it passes for -ve numbers also. I am not able to get 100 in this challenge. Can you please point what is missing?

import java.util.Scanner;

public class SortedArray {

public static void main(String[] args){
	
	Scanner sc = new Scanner(System.in);
	String sizeofArray = sc.nextLine();
	String elementsofArray = sc.nextLine();
	int[] array = new int[Integer.parseInt(sizeofArray)];
	String[] result = elementsofArray.split("\\s");
	for (int x=0; x<result.length; x++)
     array[x] = Integer.parseInt(result[x]);
 
	System.out.println(isArrayInIncreasingOrder(array,0));
 
}


static boolean isArrayInIncreasingOrder(int[] array, int selectedIndex)  {
	
	if(selectedIndex == array.length-1 ){
		return true;
	}
		
	boolean result = true;	
	for( int x=selectedIndex; x<array.length-1; ++x){
		
		if(array[x+1] > array[x])
		{
			boolean currentResult = isArrayInIncreasingOrder(array,x+1);
			result = result && currentResult;
		}
		else
			result = false;
		
		if(!result)
			break;
		
	}
	
	return result;
	
}

}

hey @connectrajanjain Your code is giving false for the input :
7
-4 0 5 5 7 9 10
But instead it should be true. Your code gives false for 5 and 5 but in the question it is stated that Increasing sequence has to be there not strictly increasing.

Hi Piyush

Thanks for finding the problem. I fixed it and all test cases passed.

Cheers
Rajan

1 Like

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.