1 test case failed

import java.util.*;
public class Main {
public static void main (String args[]) {

	Scanner sc= new Scanner(System.in);
	int len=sc.nextInt();
	int arr[]= new int[len];

	for(int i=0; i<len; i++){
		arr[i]=sc.nextInt();
	}

	Arrays.sort(arr);
	int miss=1;
	for(int i=0; i<len; i++){
		if(arr[i]==miss){
			miss++;
		}
		if(arr[i]>miss){
			System.out.println(miss);
			return;
		}
	}

	System.out.println(1);

}

}

Hello, @ANUKUL1509,
After the for loop, you should print miss instead of 1.

System.out.println(miss);
not this,
System.out.println(1);

if N = 5, and arr = [ 1,2,3,4,5]
then, your code will print 1, instead of 6

Such a silly mistake from my side. Thanks for the advice. All cases passed now.

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.