Which test case is failing?

Can I know which is the test case thats failing by any chance?

@nikhiv6,
Can you please share your code so that I can check?

Test case 1 is failing, I want to the input

import java.util.Scanner; public class Main { static int searchLastIndex(int[] arr, int i, int m) { if (i == -1) { return m; } if (arr[i] == m ) { return i; } return searchLastIndex(arr, i - 1,m ); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } int m = sc.nextInt(); int ans = 0; if(n >0){ ans = searchLastIndex(arr, arr.length-1, m); }else { ans = m; } System.out.println(ans); } }

@nikhiv6,
Corrected code: https://ide.codingblocks.com/s/206188

Mistake: You have to return -1 if the element is not present.
Example:
Sample Test Case
5
1 2 3 4 5
6
Correct Answer: -1
Your Answer: 6

In the searchLastIndex method you have to do:

if (i == -1) {
	return -1;
	}

Instead of:

	if (i == -1) {
		return m;
	}

Also your code had a lot of redundant lines in the main method, which I have removed.

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.