i know my code is wrong but can u please pin where exactly my logic fails?
K ordered lcs problem
hi @radhika1995, your logic is little flawed , what you are doing is you are making the first k characters which differs in the string into same characters but there can be cases when changing the characters afterward will give you longer lcs,
eg
6 6 1
1 2 3 4 5 6
3 10 4 10 5 10
here what your code will do is change first k (here k=1) different characters in y
x[]= 1 2 3 4 5 6
y[]=1 10 4 10 5 10
and you will get answer as 3 ( 1,4,5)
but if you would have changed 10 to 6 in y
i.e
x[] = 1 2 3 4 5 6
y[]= 3 10 4 10 5 6
and you would have gotten answer as 4 (3 4 5 6)
Refer this for explanation and code :-
thnku very much for the explanation
can u please explain why are we moving j+1,i+1 if k>0
@radhika1995, if k > 0 that means that we can change characters so we take a case in which we change b[i] to a[i], notice we made k-1 in the subsequent call ,