giving time limit error
how to optimize this code
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner obj = new Scanner(System.in);
int t = obj.nextInt();
int i=0;
while(i<t)
{
int n = obj.nextInt();
StringBuilder str=new StringBuilder("");
System.out.println("#"+(i+1)+" : "+assign(str,n));
i++;
}
}
public static int assign(StringBuilder str ,int n)
{if(str.length()==n)
{return 1;}
int t1= assign(str.insert(0,βaβ), n);
str.deleteCharAt(0);
int t2=0;
if(str.length()>0)
{if(str.charAt(0)!='b')
{t2=assign(str.insert(0,'b'),n);
str.deleteCharAt(0);}}
if(str.length()==0)
{t2=assign(str.insert(0,'b'),n);
str.deleteCharAt(0);}
return t1 + t2;
}
}