fb pixel

Algorithms and Data Structures

  • Profound Academy

    • Status
      • 1
        Implementation
      • 2
        Bitwise operations
      • 3
        Prefix Sums
      • 4
        Sliding window / Two pointers
      • 5
        Modular Arithmetic
      • 6
        Number Theory
      • 7
        Binary Search
      • 8
        Basic Sorting
      • 9
        Greedy Algorithms

  • Minimum Excluded value (MEX)

    Let’s consider the positive whole numbers (0, 1, 2, …). For a given list of numbers l, we’ll say that the minimum excluded value (MEX) of l is the smallest nonnegative integer number that doesn’t occur in l. You are asked to write a program that given the list l, would calculate its MEX.

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ ) the number of elements in the list l. The next line contains n elements representing the list .

    Output

    The program should print the MEX of the given list.

    Examples

    Input
    Output
    3 1 2 3
    0
    4 0 1 3 4
    2
    5 0 1 2 3 4
    5
     
    To check your solution you need to sign in
    Sign in to continue