# What is wrong in the recursive approach of Cakewalk (CKWLK)?

Please find me the bug in this logic.

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

bool recurse(ll n,ll original){
if(n==original){
return true;
}
if(n>original){
return false;
}

``````return (recurse(n*10,original) or recurse(n*20,original));
``````

}

int main(){
ll t;
cin>>t;
while(t–){
ll n;
cin>>n;
ll original=n;
if(recurse(1,original)){
cout<<“YES”<<endl;
}
else{
cout<<“NO”<<endl;
}
}
}

*Yes *No. , hahahahaha codechef shit!

3 Likes

It is still wrong !!! after correcting capitalisation !!!

I think it should pass…

t=100, levels in recursion tree = ~18-19, so time should be O(t*(2^19)) =O(52428800) …

1 Like

Sorry it passed… GOT AC AFTER converting YES->Yes and NO->No

https://www.codechef.com/viewsolution/27511981

yeah it passed

why this solution giving TLE?

Exactly…

Nvm… that was a different problem…

1 Like

yeah my solution was same
it should work

2 Likes

i also do not know why my recursive giving wrong answer

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
lli f(lli a,lli b)
{if(a>b)
{return 0;
}
if(a==b)
{return 1;
}
if(f(10a,b))
{return 1;
}
if(f(20
a,b))
{return 1;
}
}
int main()
{lli t,n;
cin>>t;
while(t–)
{cin>>n;
if(f(1,n))
{cout<<“Yes”<<"\n";
}
else
{cout<<“No”<<"\n";
}
}
return 0;
}

Return zero at the end of the function f.