Longest common subsequence (Dynamic programming)

sir why do you in else part write two conditions ?

hello @mzk1994

ss

are u asking about line 21 and 22?

yes these two lines…

see if character i of s1 dont match with character j at s2 then we have two options

a) discard ith character of s1 and find lcs [i+1…] of s1 and [j…] of s2
or
b) discard jth character of s2 and find lcs[i…] of s1 and [j+1…] of s2

those two line are these conditions only.

sir then why do not we just make ane call either (i,j+1) or(i+1,j)??
why we make two calls

we dont know which step will give us maximum .
thats why we are trying both ways

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.