The fundamental idea behind this problem is to break it down into smaller pieces and solve those smaller pieces, dynamic programming. So in this case lets consider a list A:
A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Notice that B[4], B[5] and B[6] are:
B[4] = (A[1]*A[2]*A[3]) * (A[5]*A[6]*A[7]*A[8]*A[9]*A[10])
B[5] = (A[1]*A[2]*A[3]*A[4]) * (A[6]*A[7]*A[8]*A[9]*A[10])
B[6] = (A[1]*A[2]*A[3]*A[4]*A[5]) * (A[7]*A[8]*A[9]*A[10])
So each step is represented as the product of the two numbers. And the component part of these products grow in a known way. So we should be able to do the computation in O(N) time with 2N operations.
Here is some code in python. I did this quickly so it might not be the most elegant code but it should demonstrate the idea:
a = [1,2,3,4,5,6,7,8,9,10]
def cct(i,b) : return str(i) + str(b)
def make_key(a):
if a:
return reduce(cct,a)
else:
return ''
partial_values = {}
def pi(a):
if not a:
return 1;
la = len(a)
hash_str = make_key(a)
if la == 1:
partial_values[hash_str] = a[0]
return a[0]
else:
if partial_values.has_key(hash_str):
return partial_values[hash_str]
else:
value = a[0] * pi(a[1:])
partial_values[hash_str] = value
return value
def f(a):
results = []
for i in range(len(a)):
beginning = a[0:i]
beginning.reverse()
end = a[i+1:]
results.append( pi(beginning) * pi(end) )
return results