## Google Interview Question

Software Developers**Country:**India

**Interview Type:**In-Person

#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";

}

}

#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";

}

}

#include<iostream>

- Anonymous November 04, 2016using 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";

}

}