Smallest Non-constructible Value
Input: A = [1, 2, 4]
Output: 8
Explanation: With subsets of A, we can construct values 1, 2, 3, 4, 5, 6, 7.Input: A = [1, 2, 5]
Output: 4
Explanation: With subsets of A, we can construct values 1, 2, 3, 5, 6, 7, 8.Solution:
def smallest_non_constructible_value(A):
# linear search
max_constructible = 0
for a in sorted(A):
if a > max_constructible + 1
break
max_constructible += e
return max_constructible + 1Last updated