Can anyone plz tell me why my code gives tle.On google search most of them have solved it using bottom top dp. Here's the lonk for problem.Is there any bug in my code or top bottom is slow due to function calls?here's the main code snippet- Code ~~~~~ for (int i = 0; i < t;) { n = scanner.nextInt(); c++; if(n==0){ break; } fib=new int[n][3]; fib1=new int[n][3]; for (int j = 0; j < n; j++) { for (int k = 0; k < 3; k++) { fib[j][k]=scanner.nextInt(); } } long s=fib(0,1); printWriter.println(c+"."+" "+(s+fib[n-1][1])); } printWriter.flush(); } public int fib(int a,int b){ if(a==n-1&&b==1){ return 0; } else if(a<0||b<0){ return 10000000; } else if(a>n-1||b>2){ return 10000000; } else if(fib1[a][b]>0){ return fib1[a][b]; } fib1[a][b]=Math.min(fib[a][b]+fib(a+1,b-1),Math.min(fib[a][b]+fib(a,b+1),Math.min(fib[a][b]+fib(a+1,b),fib[a][b]+fib(a+1,b+1)))); return fib1[a][b]; } ~~~~~