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.
/* 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.
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.
You are not printing answer in new line for first two cases
https://www.codechef.com/viewsolution/34662958
Thank you soooo much