Find Mex
Practice
3.7 (16 votes)
Algorithms
Brute force
Implementation
Linear search
Iterators
Problem
69% Success 8415 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an integer array of length \(N\). You have to find \(MEX\) of \(i^{th}\) element for all \(1 \leq i \leq N\).
\(MEX\) of the \(i^{th}\) element is the minimum element greater than or equal to \(0\) which is not present in array till the \(i^{th}\) index.
Input Format:
First line contains an integer \(N\) denoting the size of array.
Next line contains \(N\) integers denoting the elements of the array.
Output Format:
Print \(N\) integers. \(i^{th}\) element should be the \(MEX\) of the array prefix till \(i\)
Constraints:
\(1 \leq N \leq 2*10^5 \\ 0 \leq arr[i] \leq 2*10^5 \)
Submissions
Please login to view your submissions
Similar Problems
Points:10
66 votes
Tags:
AlgorithmsBrute ForceC++Searching
Points:10
6 votes
Tags:
Linear SearchAlgorithmsGreedy algorithm
Points:10
195 votes
Tags:
AlgorithmsEasySearching
Editorial