@taran_1407
There should be atleast 2-3 examples with proper explanations for each example. Also, the question description was really bad.
Checkout Leetcode or Hackerrank. They give plenty of examples with proper explanations to each one of the example.
Please take this as a constructive criticism. Thanks.
I agree with you totally Brother.It Took me 1 Hour to interpret what the question is asking to do.Problem Statement was a bit confusing.
I also asked in comments of 2nd problem but no one replied me.
Thanks @adarsh08x for the reply.
E.g.
1
6 6
4 5 7 8 9 10
According to your post following test case should return the total length of the array.
I have looked at the editorial code which is written in Java. But the output is returned as -1.
yes it will return -1 because 1,2,3, are not present in the in the array
just add 1,2,3 then it will return the whole length
my solution
/* 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);
}
}
}
}
What is wrong in this code? It is giving WA.
Can anyone please help me find a mistake with my code. Have spent hours but couldn’t get. All the manual test cases which I could think of gets passed but Codechef says Wrong Answer.
Pls help guys… https://www.codechef.com/viewsolution/34646376
Worst explanation of the question i have ever seen till now.
thanks for your time bro… actually m*(m-1)/2 will be of long long type and i had taken int. it got AC now doing this. Repeated element I had taken care by counting only 1 instance of no. < m by using map. once again, thanks for your time. let me know if I can return the favor if its feasible for me.
You have to first take input for n and then for m.
thanks!
author should have explained MEX more clearly in the contest problem.
simple problem though
are out your mind
there is written ‘among’ and we are allowed to choose our own sequence
to make max length .
1
6 6
4 5 7 8 9 10
for this i will choose[4 5 7 8 9 10] as there 6 is missing.
Chef has a sequence of positive integers A1,A2,…,ANA1,A2,…,AN. He wants to choose some elements of this sequence (possibly none or all of them) and compute their MEX, i.e. the smallest positive integer which does ----not occur among the chosen elements----. For example, the MEX of [1,2,4][1,2,4] is 33.
note that ---- ---- we are allowed choose our own sequence to make m=6.
question is wrong.
m should be defined as lowest positive integer which is not present.
that is wrong not confusing
mex should be defined as lowest positive integer >=1 .
and ‘among’ must not be used.
exactly.
bro its not poorly defined it is wrongly defined.
mex should be defined as lowest positive integer >=1 .
and ‘among’ muuuuuuuuuuuust not be used. must not
bro its not poorly defined it is wrongly defined.
mex should be defined as lowest positive integer >=1 .
and ‘among’ muuuuuuuuuuuust not be used. must not
bro its not confusing it is wrongly defined.
mex should be defined as lowest positive integer >=1 .
and ‘among’ muuuuuuuuuuuust not be used. must not
Very very poorly defined question, atleast give one more test case for clarity. That’s why people prefer codeforces instead of this.
Yes That ‘Among’ Word was an obstacle in understanding the problem.
EXACTLY!!!