## rahulkumarsk2015

BAN USERUsing kmp algorithm we can solve in n^3

- rahulkumarsk2015 May 30, 2018First calculate the root node... Then recursively call for left and right child to make complete bst

- rahulkumarsk2015 May 29, 2018It can be done in m*n*n using kadane algorithm.. Taking each pairs of column and try to apply the kadane in every row

- rahulkumarsk2015 May 28, 2018#include<bits/stdc++.h>

using namespace std;

int main()

{

int t;

cin>>t;

while(t--)

{

int n,i,j,cnt=1;

cin>>n;

char p[n];

string str[n];

for(i=0;i<n;i++)

cin>>p[i];

for(i=0;i<n;i++)

cin>>str[i];

for(i=0;i<n-1;i++)

{

for(j=i+1;j<n;j++)

{

if(p[i]==p[j])

{

if(str[i]!=str[j])

{

cnt=0;

}

}

if(p[i]!=p[j])

{

if(str[i]==str[j])

{

cnt=0;

}

}

if(cnt==0)

{

cout<<"n0";

break;

}

}

if(cnt==0)

{

break;

}

}

if(cnt==1)

{

cout<<"yes";

}

}

}

#include<iostream>

using namespace std;

int main()

{

int t;

cin>>t;

while(t--)

{

int n,i,j,k,l;

cin>>n>>k>>l;

float ar1[n+1][n+1];

for( i=0;i<=n;i++)

for(j=0;j<=n;j++)

{

ar1[i][j]=0;

}

ar1[1][1]=n;

for(i=2;i<=n;i++)

{

for(j=1;j<=i-1;j++)

{

ar1[i][j]=(ar1[i-1][j]-1)*1.0/2;

ar1[i][j+1]=(ar1[i-1][j]-1)*1.0/2;

}

}

if(ar1[k][l]>0 && ar1[k][l]<=1)

cout<<ar1[k][l];

if(ar1[k][l]>1)

cout<<"1";

else

cout<<"0";

}

}

#include<iostream>

using namespace std;

int main()

{

int t;

cin>>t;

while(t--)

{

int n,i,j,k,l;

cin>>n>>k>>l;

float ar1[n+1][n+1];

for( i=0;i<=n;i++)

for(j=0;j<=n;j++)

{

ar1[i][j]=0;

}

ar1[1][1]=n;

for(i=2;i<=n;i++)

{

for(j=1;j<=i-1;j++)

{

ar1[i][j]=(ar1[i-1][j]-1)*1.0/2;

ar1[i][j+1]=(ar1[i-1][j]-1)*1.0/2;

}

}

if(ar1[k][l]>0 && ar1[k][l]<=1)

cout<<ar1[k][l];

else

cout<<"0";

}

}

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

We can use dynamic programming... Dp[I] will store the total number from last position.. Dp[i+1]=dp[i]+dp[i-2];

- rahulkumarsk2015 May 30, 2018