Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Maximum Number of Consecutive Values You Can Make

XPChallenge Points: 20
levelLevel: Medium

You are given an array coins where each element represents the value of a coin you own.
A value x can be formed if there is a subset of coins that add up exactly to x.

Your task is to determine the maximum count of consecutive values that can be created starting from 0 without any gaps.

You are allowed to use any subset of coins, and you may have duplicate coin values.

Return how many continuous values starting at 0 can be constructed.

Example 1:

Input: coins = [1,2]

Output: 4

Explanation:

You can form: - 0: [] - 1: [1] - 2: [2] You can form 0, 1, and 2 → total = 3 consecutive values.

Example 2:

Input: coins = [2,1,1]

Output: 5

Explanation:

Possible sums: 0, 1, 2, 3 → total = 4 values.

Example 3:

Input: coins = [1,2,5,10]

Output: 4

Explanation:

You can make values: 0,1,2,3 → but cannot make 4 → so answer is 4.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result