K-ordered-lcs(dynamic programming)

what is the approach of this que?

The idea is to use Dynamic Programming. Define a 3D matrix dp[][][], where dp[i][j][k] defines the Longest Common Subsequence for the first i numbers of first array, first j number of second array when we are allowed to change at max k number in the first array.
Therefore, recursion will look like

why we need 3-d matrix?

because the state is dependent on 3 parameters
i , j , k
like in simple LCS
u have state dependent on i , j
and now u are allowed to change at max k number in the first array. so k needs to be mantained such that we do not superceed the max value of k

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.