taken holds numbers that are already in use (positive integers, possibly repeated). You must hand out count more numbers: they all have to be distinct positive integers that do not appear in taken.
Pick them so that their sum is as small as possible and return that sum.
Note that count can be very large, so handing the numbers out one at a time will not do.taken=[2, 5, 3], count=3 → 11
The free numbers are 1, 4, 6, 7, … The three smallest give 1 + 4 + 6 = 11.
taken=[100, 100], count=4 → 10
Numbers 1, 2, 3, 4 are all free and sum to 10. The repeat in taken changes nothing.
taken=[1, 2, 3], count=2 → 9
The first three numbers are taken, so we pick 4 and 5: the sum is 9.
taken=[2, 5, 3], count=3
11
Run checks the first 3 tests in your browser. Submit checks all 113 tests on the server, hidden ones included.