Here in the solution, bhaiya wrote this line in for loop of solution
ans = max(ans, a[left]*a[right]*a[pivot] + Solve(left, pivot) + Solve(right, pivot))
But in the start we are passing left as 0 and right as n+1
So for example n = 5 and a = {4,5,3,6}
so bhaiya first appended 1 at both sides so our array becomes - {1, 4, 5, 3, 6, 1}
and he called on the recurrsion function for the array.
So when pivot is for example = 2 and a[pivot] = 5
bhaiya multiplied a[left] with a[right] and with a[pivot]
But my point is left and right for pivot = 2 is (pivot-1) and (pivot+1). so why bhaiya multiplied with a[left[ and a[right] ???
As in question it is written that we have to multiply with immediate left and immediate right elements for any ith element.