Why am i getting segmentation fault..the code looks perfectly fine to me

Hey @neha_153 the vector container is initially empty so you cannot directly access elements without reserving size!
do it this way vector<vector< int> >dp(n+1,vector(m+1,-1))
also pass dp and strings by reference else you will get TLE/MLE

it worked thanks!!!

i had to reopen sorry as it did not pass the last test case

Yes it’s strange (try bottom up DP as I don’t see any fault in your code!)
your code prints no output for
xevqqkiqskgfvzbtlnprtpjopoelvpzelyzopwqngtaftvmy
bbjjfx
even as LCS is of length 3.
build DP with bottom up approach!

i tried bottom up its not working still :disappointed:

Share your code! moreover this is also by bottom up and works fine!