Practice Problems on MEX

MEX (Minimum Excluded) in Competitive Programming

MEX of a sequence or an array is the smallest non-negative integer that is not present in the sequence.

Example:

  • If we have a sequence S[] = {1,2,0,4,5} then MEX (S) = 3.
  • If we have a sequence S[] ={2,0,3,10} then MEX (S) = 1.
  • If we have a sequence S[] ={1,2,3,4,5} then MEX (S) = 0.

Note: The MEX of an array of size N cannot be greater than N since the MEX of an array is the smallest non-negative integer not present in the array and array having size N can only cover integers from 0 to N-1. Therefore, the MEX of an array with N elements cannot be greater than N itself.

Similar Reads

How to Find MEX of an array (Without Updates) ?

Given an array arr of size N, the task is to determine the MEX of the array....

How to Find MEX of an array (With Updates) ?

...

How to solve MEX related problems in Competitive Programming ?

...

Practice Problems on MEX:

...

Contact Us