Wrong base case

please check my code;

import java.util.*;

public class Main {

public static void main(String args[]) {

Scanner sc=new Scanner(System.in);

int t=sc.nextInt();

while(t–>0){

int n=sc.nextInt();

int m=sc.nextInt();

System.out.println(helper(n,m));

}

}
private static int helper(int n,int m){
	if(n==1 ){
		return 1;
	}
	if(n==0)
	return 1;
	if(n<0)

return 0;

	return helper(n-1,m) +helper(n-m,m);
	
}

}

Hello @S18CRX0174,

Yes, the base cases are wrong.
It should be:
//There is only one way of placing tiles for this case i.e. all vertically:
if(n<m)
return 1;

//There are two ways to place tiles for this case i.e. either all vertically or all horizontally:
if(n==m)
return 2;

BTW, you might get TLE after writing your code though it would be logically correct.
This is because it is a problem of Dynamic Programming.

Hope, this would help.
Give a like if you are satisfied.

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.