YES but your code prints 3.
Man you should have specified chosen elements should start from —“1”—
, statement felt incomplete…just a suggestion for you guys for next time.
Can we have integers in jumbled order since the question does not talk about ordering of the sequence?
Tester’s solution is wrong it should be (i<m) instead of (i!=m).
I think the test cases for this problem are weak. What will be the answer if you are given the following test case?
1
10 4
1 2 3 5 6 8 9 10 11 12
CodeChef: Practical coding for everyone has passed all the test cases but fails for the above test case.
My code gives 5 as the answer which I think is correct but his code gives 10. Please check the test cases for this problem @rezwanarefin01 @raja1999.
hey if the input is 4 5 6 8 9 and M=7 then what should be output
What if the input is 4 7 8 and M=5 what should be the output
Isn’t the correct answer 10? You can choose all the numbers in the sequence and the smallest number which does not exist in this sequence is 4. Hence the answer is 10?
I found the statement confusing, quite honestly. Please try to give at least 2 test cases with proper explanation, I ended up confused about what MEX actually is, “chosen” is the word that killed my rating.
This is the confusing part, MEX is the smallest positive integer which doesn’t occur in the set, hence, the answer will be -1. Because MEX of 4 7 8 is 1.
To clarify, look at the code:
int mex=1;
while(s.count(mex)){
mex++;
}
The answer is mex when the while loop breaks. So you take a set and start checking if 1 occurs, then you proceed to 2,3,4 and so on. until you find the one element that doesn’t occur, this shall be considered as MEX of the given Set.
The statement was confusing and a test case explaining the whole scenario would’ve gone a long way for us.
-1
You understood the problem wrong.
7 is also not present in the sequence.
My day is ruined and my disappointment is immeasurable.
ok now I got it. Thanks man
Such poorly explained problem. They should have clarified that we need to choose subsequence of array rather than subarray , it was just written choose largest no. of elements (In what) . A problem should be easily understandable . But everything has a learning next time whenever there is written choose largest number , I will assume it to be subsequence .@rezwanarefin01 @raja1999
Right…this also happened to me.
Question was poorly defined.
Question says
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
If we go by this logic than for input
1
9 8
1 2 3 5 6 7 9 10 11
The output should be [5,6,7,9,10,11] i.e 6. But according to the solution provided it is different.
Poorly defined question
Yeah I got it. Thanks man