![]() |
VOOZH | about |
You are given an array arr[] of size N, the task is to determine the MEX of the array.
MEX is the smallest whole number that is not present in the array.
Examples:
Input: arr[] = {1, 0, 2, 4}
Output: 3
Explanation: 3 is the smallest whole number that is not present in the arrayInput: arr[] = {-1, -5, 0, 4}
Output: 1
Explanation: 1 is the smallest whole number that is missing in the array.
Approach: Follow the below idea to solve the problem
Sort the array in increasing order and find the first number starting from 0 which is not present in the array.
Follow the steps to solve the problem:
Below is the implementation of the above approach:
3
Time Complexity: O(N * logN)
Auxiliary Space: O(1)