TCS Coding Problem 4

2 comments on “TCS Coding Problem 4”


  • Mohd Saif

    PYTHON CODE:

    def lcs(X, Y, m, n):

    if m == 0 or n == 0:
    return 0;
    elif X[m-1] == Y[n-1]:
    return 1 + lcs(X, Y, m-1, n-1);
    else:
    return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));

    X,Y=map(str,input().split(” and “))
    print(“Length of LCS is “, lcs(X , Y, len(X), len(Y)))


  • Saurabh Patidar

    #include
    void main()
    {
    char arr[6],brr[6],crr[6];
    int i,j=0,k=1,m=0;
    printf(“enter first string”);
    gets(arr);
    fflush(stdin);
    printf(“enter second string”);
    gets(arr);
    printf(“%s\n”,arr);
    for(i=0;i<6;i++)
    {
    if(j!=k)
    {
    for(j=0;j<6;j++)
    if(arr[i]==brr[j])
    {
    crr[m]=arr[i];
    m++;
    k=j;
    break;
    }
    }
    else
    {
    for(j=k+1;j<6;j++)
    {
    if(arr[i]==brr[j])
    {
    crr[m]=arr[i];
    m++;
    k=j;
    break;
    }
    }
    }

    }

    printf("%d",c);

    }