Sort the array. Any "middle" numbers not in the first 3 or last 3 cannot be used in the final answer. If we are using a middle number, it must have both a left-neighbor and a right-neighbor, and switching to one of these neighbors will increase the product.

```
def maximumProduct(self, A):
A.sort()
if len(A) > 6:
A = A[:3] + A[-3:]
return max(A[i] * A[j] * A[k]
for i in xrange(len(A))
for j in xrange(i+1, len(A))
for k in xrange(j+1, len(A)))
```