Tất cả thử thách
Trung bình 0 đã giải Tỷ lệ chấp nhận 0%

Smallest Missing Coin Sum

Find the first positive amount that cannot be made from the available coins.

You may select any subset of the supplied coins. Each individual coin may be used at most once, even when multiple coins share a value. Find the smallest positive integer amount that no selection can produce.

Implement missing_coin_sum(coins).

Input

coins: The values of the available coins; duplicates represent separate coins.

Output

Return the smallest positive impossible amount.

Ràng buộc

1 ≤ number of coins ≤ 200,000. Each value is between 1 and 1,000,000,000.

Ví dụ

Ví dụ 1
Đầu vào:
coins = [1, 1, 4]

Kết quả mong đợi:
expected = 3
Đầu vào:
std::vector<long long> coins = {1, 1, 4};

Kết quả mong đợi:
long long expected = 3;
Đầu vào:
long[] coins = new long[] {1, 1, 4};

Kết quả mong đợi:
long expected = 3;

Giải thích

Amounts 1 and 2 use the one-valued coins. No available subset totals 3.

Ví dụ 2
Đầu vào:
coins = [2, 3]

Kết quả mong đợi:
expected = 1
Đầu vào:
std::vector<long long> coins = {2, 3};

Kết quả mong đợi:
long long expected = 1;
Đầu vào:
long[] coins = new long[] {2, 3};

Kết quả mong đợi:
long expected = 1;

Giải thích

There is no way to make 1 because every coin is worth at least 2.

Tham khảo

Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.

Học hỏi từ người khác

Giải pháp cộng đồng

Chưa có giải pháp nào được chia sẻ. Hãy giải thử thách này để đăng giải pháp đầu tiên.