printLCS. cant understand where i'm going wrong with the solution

attempt link : https://ide.codingblocks.com/s/46943

i’m kind of struggling with dp. starting with the questions. would be realy helpful if you could point out my mistake.

question:
PRINT LCS
A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence {A,B,D} is a subsequence of {A,B,C,D,E,F}, obtained after removal of elements C, E and F.

Given two strings A and B of size n and m respectively, you have to print the Longest Common Subsequence(LCS) of strings A and B, where LCS is the longest sequence present in both A and B.

Note: It is gauranteed that there is only one unique longest common subsequence

Input Format:
Two strings A and B.

Constraints:
1 <= n,m <= 10^3

Output Format
Output the LCS of A and B.

Sample Input
abc
acd
Sample Output
ac

https://ide.codingblocks.com/s/46947

I have made a small change. Check this code now.

still not passing the testcases

TESTCASE #1: run-error (Time: 0 s)
TESTCASE #2: wrong-answer (Time: 0 s)

i dont know about the test cases but it is performing well for some self defined test cases that [reviously it wasnt giving the right ans for. what was wrong in using that substring line.

Firstly, add the problem link so that i can verify your code.
Second, run-error may be due to constraints. string lengths may be >100.

question link : https://hack.codingblocks.com/contests/c/141/277

run error resolved but still shows wrong answer.

please elaborate about why you replaced substring too.

thankyou for your support

https://ide.codingblocks.com/s/46978

“There is only one unique LCS”. This line written in the question is incorrect because opt1>=opt2 worked and passed both the cases.

You can check it in the code attached.

Using substr was not wrong, but the usage was wrong. You want substring from m to m+1, this means you want a substring starting from m and of length 1. So use, x.substr(m,1). Second parameter is length and not the ending position.

thankyou so much sir.