Failing all test cases

https://ide.codingblocks.com/s/72418

can you help me with this code. It is failing all test cases

Hey Sanyam,
You are decreasing k and increasing i and j.
I dont think so it is making any sense.
DP means use of already solved subproblems.
you need to compute DP[n][m][k]…this is answer
So,
If A[i] != B[j],
… dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j - 1][k], dp[i - 1][j - 1][k - 1] + 1)
If A[i] == B[j],
… dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j - 1][k], dp[i - 1][j - 1][k] + 1)

Try this recursion. I hope u r getting this.

But isn’t it the same code that is written and submitted in the video itself??
can you help me on that please??

If I choose to change a number to other one
then in this case, if my k > 0, i will change the number and move on increasing both i and j and reducing k by 1.
Nothing wrong with this I guess. :slight_smile:

I have not seen the video…Mention video link.
And it totally depends how you define state of DP at any point
Like
My
Dp[i][j][k] is LCS of string 1 upto index i and string 2 upto index j with use of atmost K swaps.

Mention your state.
What your Dp[i][j][k] represents?

https://online.codingblocks.com/player/10892/content/1275/172

– video link

https://ide.codingblocks.com/s/72418

this works, got my mistake.
Thanx mate!

As you got your mistake and this doubt is resolved . I am marking it resolved.
If your think your doubt is not resolved then u can reopen this thread.

1 Like

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.