Run Errror-- This is the code giving run error for test cases, Running with the sample test case gives correct output

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int num=0,st[];
int n=sc.nextInt();

 for(int i=1;i<=n;i++){
	 num=sc.nextInt();
	 	 st=new int[num+1];
 System.out.println("#"+num+" : "+fibonacci(num,st));
 
 }


}

public static int fibonacci(int n,int st[]){
	if(n==0)
	return 0;
	if(n==1)
	return 2;
	if(n==2)
	return 3;
    if(st[n]!=0)
	return st[n];
	else{
	int res=fibonacci(n-1,st)+fibonacci(n-2,st);
	st[n]=res;
	return st[n];
	}
}

}

Firstly, the logic is not correct. You haven’t accounted for the fact the there SHOULDN’T be two consecutive b’s. You have just hardcoded all the cases for the sample test, so it passes the sample test case.

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.