Minimum Excluded

In a given set of integers, the “mex” or the minimum excluded value is the smallest non-negative integer that is not present in the set. For example, the mex of the set {0,1,2,4} is 3.


This is a companion discussion topic for the original entry at https://toph.co/p/minimum-excluded

I am getting runtime error for the following code:

    BitSet b = new BitSet(1000000001);
    Reader sc = new Reader();
    int n = sc.nextInt();
    while(n-->0) b.set(sc.nextInt());
    System.out.println(b.nextClearBit(0));

any idea why?