TCS Coding Problem 4

7 comments on “TCS Coding Problem 4”


  • Anshul

    def lcs(a,b):
    c=len(a)
    d=len(b)
    print(“Max Length is: \n”,max(c,d))

    a=input(“Enter your string: \n”)
    b=input(“Enter your string 2: \n”)

    lcs(a,b)


  • Ayush

    # Longest common subsequence

    a, b = input().split()

    def lcs(a, b):
    len_a = len(a)
    len_b = len(b)
    arr = [ [0 for j in range(len_b + 1)] for i in range(len_a + 1)]
    #print(arr)
    for i in range(len_a):
    for j in range(len_b):
    if i == 0 or j == 0:
    arr[i][j] = 0
    elif a[i-1] == b[j-1]:
    arr[i][j] = arr[i-1][j-1] + 1
    else:
    arr[i][j] = max(arr[i-1][j], arr[i][j-1])
    print(arr)
    return arr[len_a-1][len_b-1] + 1

    print(lcs(a, b))


  • jyothish

    #include
    #include
    int main()
    {
    int count = 0,i,k;
    char X[] = “AGGTAB”;
    char Y[] = “GXTXAYB”;
    int m = strlen(X);
    int n = strlen(Y);
    for(i=0;i<m;i++)
    {
    for(k=0;k<n;k++)
    {
    if(X[i]==Y[k])
    {
    count = count+1;
    Y[k]= ' ';
    break;
    }
    }
    }
    printf("%d",count);
    return 0;
    }


  • Raman

    a=input()
    b=input()
    l=[]
    for i in a:
    c=0
    for j in b:
    if i==j:
    c=1
    if c==1:
    l.append(i)
    c=set(l)
    print(“”.join(c))
    print(“of lenth”,len(c))


  • Richik

    #include
    #include
    #include
    using namespace std;
    /* run this program using the console pauser or add your own getch, system(“pause”) or input loop */
    int findthat(string k,string a){
    setc;
    int count=0;
    for(int i=0;i<k.length();i++){
    c.insert(k[i]);
    }
    for(int i=0;i>k>>a;
    cout<<findthat(k,a);
    return 0;
    }


  • 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);

    }