CAn you tell me my mistake?

Hi Vageesha.
every time u see s[i] == p[j] u cant just consider it to be a part of LCS. it may or may not. this this is not the correct approach. Basically u have to backtrace it. You may find video solution for the same.
image

I have corrected ur code

if ur doubt is cleared mark the doubt as cleared and do give ur valuable feedback

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.