Dp-wine problem

someone plz explain how to fill upper half of 2-d array video is not clearly uploaded

mainly sliding window part

It is very well explained in the video. See the code there and dry run yourself to understand well. You will have to fill the array starting from the first diagonal.Then you will fill the cells above that using the dp relation as derived in the video. You can see that the cells are being filled in diagonal order. So multiple loops are used to iterate diagonally and move upwards till the top right corner.

Hi Deepak , first u need a clear understanding of what dp[i][j] is
dp[i][j] is the maximum profit we will get if there are arr[i] to arr[j] wine bottles left , now that would only be possible when 0 to i-1 bottles are already picked before and j+1 to n-1 bottles are already picked and we know to pick each bottle we take 1 year so to reach the state when arr[i],arr[i+1]…arr[j] bottles are left in the table n-(j-i)+1 year must have passed .

you want to know how we are filling the array
first we are considering that only 1 wine bottle is left and then two wines bottle and so on .
len denotes the number of wine bottles present in the table and we are considering all the scenarios in which len bottles can be present , in case of len =2 and n=5. then possible bottles that can be present will be {0 1}{1 2}{2 3}{3 4} so if we have len bottles and starting index is i and ending index is j then we can find its value as mentioned before using dp[i][j-1] and dp[i-1][j] note that the length of [i,j-1] and [i-1,j] state is len-1 which we have already computed so this is how we reach the state {0 - n-1} and return the answer

In case of any doubt feel free to ask :slight_smile: