My Code is giving wrong output after copying the same as in video

I am sending my code . It is Valentine magic problem.

By solving it by dp , i got wrong answer.

Please explain why? //Output should be 1 instead of 0.

Why this happens?

@ShubhamK97 hey have correcetd you code,please check: