# Help needed in DP question

Remove array end element to maximize the sum of product.
question link: Remove array end element to maximize the sum of product - GeeksforGeeks
I am not able to do it with Tabulation method.
Can anyone help me in writing the code via tabulation method.

dp[i][j] stores the answer for the range [i, j]. So we can either pick A[i] next and add the answer for range [i+1, j] or we can pick A[j] and add the answer for range [i, j-1]. And also, the final answer will be dp[n-1]. So, for doing it bottom up, we can have the following base cases : dp[i][i] = A[i] * n. For all 0<=i<n. Then, dp[i][j] = max(A[i] * (n-j-i) + dp[i-1][j], A[j] * (n-j-i) + dp[i][j-1]).

Thanks …
But I have a doubt. Hope you will clear it.

1. In base case .dp[i][j]=A[i]n. Actually in this case you are looking in subarray (i…i) (starts at i and ends also at i)
So for this… Number of elements already removed are 0 because there is only one element in this subarray. Hence answer should be A[i]