Do not change the dp array for j less than arr [ i ]
if ( arr [ i ] <= j ) : NEW_LINE INDENT if ( arr [ i ] == j or dp [ j ] or dp [ ( j - arr [ i ] ) ] ) : NEW_LINE INDENT dp [ j ] = True NEW_LINE DEDENT else : NEW_LINE INDENT dp [ j ] = False NEW_LINE DEDENT DEDENT j -= 1 NEW_LINE