--:--:--
🟢 🟡 🔴
greedysorting

Max Prefix MEX

Given an array A of N non-negative integers. Find the maximum K such that there exists a permutation of A for which the set of its prefix sums contains all integers 0, 1, ..., K-1. Input: N followed by N integers. Output: Single integer K.

3 0 1 3
2
3 1 2 3
0
0
0%
1