can anyone send bottom up approach of question valentine magic
Doubt in valentine magic problem
the dp recurrence is
dp[i][j] = min(dp[i][j+1],dp[i+1][j+1]+abs(a[i]-b[j]))
with i goes from n-1 to 0
and j goes from m-1 to 0
Also for base case, initialize dp[i][m]=INT_MAX for i from 0 to n-1 and dp[n][m]=0
also dp[n][j] = 0 for j from 0 to m-1.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.