I used hash map can you please tell why it isnt passing all the test cases?
hello @gaganpreetsachdev1
In lcs order matters,ur code logic is not considering order hence it will produce wrong result.
hint -> try to extend lcs logic on 3 string
I used LCS logic can you check my code once
Are you gonna reply???
I have a general doubt while memoisation is it necessary to initialize dp array as -1 ? cause many times when i intitialize the dp array with 0 it doesnt pass all the test cases.
@gaganpreetsachdev1
we need to initilaise dp array with such a value using which we can distinguish new and previoulsy visited state.
in most of the time answer is non negative so in that case intialisation with any negative number works
check ur updated code->
a)declare dp array globally (local dp array will give segementation fault)
b) instialise it with -1
c) in max1 function use >= in place of > (otherwise it will return wrong max)
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.