Help in MAXMEX

solution:CodeChef: Practical coding for everyone
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. CodeChef: Practical coding for everyone

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. :slight_smile:

OKay, thank you for the help.

submission: CodeChef: Practical coding for everyone

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!

This is not your submission link

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

Here it is, kindly please help
Submission: CodeChef: Practical coding for everyone

Btw, you should click one more time and send link to that submission which you have doubt (by clicking on view and then sharing submission link). I donā€™t know much about java but I will try.

https://www.codechef.com/viewsolution/34661379

There we go. Any help will be appreciated.
Thanks!

You are not printing answer in new line for first two cases
https://www.codechef.com/viewsolution/34662958

Thank you soooo much :innocent: