Tilling Problem _ II COde gives TLE

Can you pls tell wh my code gives tle? I think it’s complexity is O(n) only which shouldn’t give tle.


int tile(int n, int m)
{

if(n==1 | n<m) return 1;
else if( n==m ) return 2;
else {int ans = tile(n-1,m) + tile(n-m,m);
return ans;}

}

int main()

{

int t; cin>>t;
while(t--)
{
	int n,m;
	cin>>n>>m;
	int ans=1;
	int tiles = tile(n,m);
	cout<<tiles<<endl;
}
return 0;

}

hi @snehacpcb_6a154f5c45187387 code is correct use dp to optimise it

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.