Help in MAXMEX

solution:https://www.codechef.com/submit/MAXMEX
Why is it giving WA? IF anyone can tell any test case where this code will fail, it would be a great help.

You have not posted your submission, rather a way to submit the solution of the problem.

Also, it would be better if you would ask this question in the editorial post where you might get your answer reading other peopleās doubts.

1 Like

/* package codechef; // donāt place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be āMainā only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i=i+1)
{
int n=sc.nextInt();
int m=sc.nextInt();
int array[]=new int[n];
for(int j=0;j<n;j=j+1)
{
array[j]=sc.nextInt();
}
Arrays.sort(array);

``````	    //Find Mex
int x=1;
for(int j=0;j<n;j=j+1)
{
if(x<array[j])
{
break;
}
x=array[j]+1;
}
//System.out.println(x);
if(x==m)
{
System.out.println(n);
}
else if(x<m)
{
System.out.println("ā1");
}
else if(x>m)
{
int count=0;
for(int j=0;j<n;j=j+1)
{
if(array[j]==m)
count=count+1;
}
System.out.println(n-count);
}
}
}
``````

}

I have made some changes in your code and now it works. https://www.codechef.com/viewsolution/34649106

Idk but your code was printing `?1` instead of `-1` in invalid cases. I guess thatās why you were getting the wrong answer verdict.
P.S - you hadnāt imported all the required libraries, so keep that in mind in the future.

OKay, thank you for the help.

submission: https://www.codechef.com/submit/MAXMEX

I have implemented editorials approach, All my custom test cases are getting correct output but Iām getting wrong answer after submission. kindly please help with some test cases!

Okay I got it , I need to share the link from mySubmssion page, right?