# Find the smallest positive integer value that cannot be represented as sum of any subset of a given array in Python

PythonServer Side ProgrammingProgramming

Suppose we have a sorted array of positive numbers, this array is sorted in ascending order, er have to find the smallest positive value that cannot be represented as sum of elements of any subset of given set. We have to solve this problem in O(n) time.

So, if the input is like A = [1, 4, 8, 12, 13, 17], then the output will be 2.

To solve this, we will follow these steps −

• n := size of A

• for i in range 0 to n, do

• if A[i] <= answer, then

• otherwise,

• come out from the loop

## Example

Let us see the following implementation to get better understanding −

Live Demo

def get_smallest_element(A):
n = len(A)
for i in range (0, n ):
else:
break
print(get_smallest_element(A))
[1, 4, 8, 12, 13, 17]
2