So, we have to start every sequence by assuming it starts with 1.
like in [4,7,8,9,10] MEX = 1 and if m=6 or 5 then answer will be -1.
I can see only one problem in the solution… Since repeated elements are allowed, it’s not guaranteed that the sum of elements smaller than m present in the array is m * (m - 1)/2. We have to check it using either a set or hashtable.
Can someone help me figure out the test cases??
3
4 3
1 2 4 5
6 3
1 2 4 6 7 8
6 3
1 4 5 6 7 8
According to me output should should be : 4 6 1
Am I right or wrong?
In the test case provided by you - MEX(i.e X) exists and is equal to 7 and the code will return or print 5.
You can check my solution here
I hope it helps you ![]()
Last one should be -1 since 2 is absent.
Shittiest problem statement ever, should’ve better explained maybe
Atleast 2 sample test cases must have been there. Even the confusing problem statement can be ignored if we look at multiple sample test cases. With only 1 sample TCs, many got WA!
in that case mex will be 1
- It is not necessary that input starts from 1, if m>1 and 1 is not present then the answer will be -1 always as 1 is the smallest positive integer.(every positive integer up to m-1 should be present otherwise answer will be -1)
- Order of the input don’t matter i guess, since only the presence of element matters.
for this array A mex will be 7 and largest posible sequence with mex=6 is {1,2,3,4,5}
No where it was told that duplicate element can be present, later on it was mentioned in comments.
Also please take good examples in explanations.
Codechef needs learn alot from codeforces.
can anyone tell me code to find mex here in c language
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.