Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Sunday, December 31, 2017

Distinct Occurrence of a string


Code:

class dmg
{
int count(String a,String b,int i,int j,int l1,int l2)
{
if(j==l2)
return 0;
int c=0;
while(i<l1 && (l1-i)>=(l2-j))
{
if(a.charAt(i)==b.charAt(j))
{
if(j==l2-1)
++c;
else
c+=count(a,b,i+1,j+1,l1,l2);
}
++i;
}
return c;
}
    int subsequenceCount(String S, String T)
    {
return count(S,T,0,0,S.length(),T.length());
    }
}

0 Comments:

Post a Comment

Stats