No, the MEX will be 1 in this case.
MEX for the sequence u have chosen is 1(not necessary for it to be present in your chosen sequence).
Thanks brother. But I don’t think that would be correct. because if that would have be correct than
MEX for [1,2,4] would also have been 1.
so thats why question had (possibly none or all of them) in it which tell the whole array or -1 in all cases.right?
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 is 3.
Please help on How it is 1.
Mex is the smallest positive integer that is not present in the sequence, in the following test case , that number is 4 hence no sequence can be formed out of the given sequence which has mex=8;
Input:
1
7 4
1 2 3 4 4 5 7
here answer should be: [1,2,3,5,7] because mex element in this case would be 4.
happy coding .
You have three integers in the array- 1,2,4. Now, look at its complement set but only include positive integers(mind that in the question it is given positive integers, not non-negative integers, otherwise 0 also comes into play). So, our complement set includes {3,5,6,7,8…}. Choose the smallest integer within this set. Voilà!, you get your answer which is 3.
Hope this helps.
Thanks, I agree to your logic but I think the question provides some different defination-
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.
Thanks, but I think, ‘’ either ‘’ would have been a better option than ‘‘possibly’’.
i.e
‘‘either none or all of them’’
Yup i was also confused and thought like you and i made an solution for it but as you know it was getting WA.I nearly spent 40 min on it.
I also agree that the question was not written well and thus made us confused
Same, I really felt sad as it wasn’t that hard of a problem!
bro you are considering set of positive integers as the set of numbers given in the array.
but for[2,3,4,5,8] smallest possible positive integer will always be 1.
compute their means after you choose the elements from the array.
eg- array being: 1,2,4,6,8 and i choose 2,4,6,8 then the smallest possible integer that is not present in the sequence is 1 and not 3.
What should be the output of-
1
5 4
1 2 5 6 7
-1 ,as MEX of sequence < M
Yes, it should be -1, but many accepted solutions are giving output as 5
Thanks Brother, that was helpful. 
Not possible.
If so, test cases were weak. It is surely wrong.
Post at least one such solution to support your claim.