Problem shows TLE

What is the issue in this code?
The question is Palindromic Queries.
The code which I have given shows TLE.
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String str = sc.next();
str = str.substring(0,n);
int m = sc.nextInt();
for (int i = 0; i < m ; i++) {
int l = sc.nextInt();
int r = sc.nextInt();
boolean[][] dp = new boolean[n][n];
if(count(str,l-1,r-1,dp)){
System.out.println(“YES”);
}
else{
System.out.println(“NO”);
}
}
}

public static boolean count(String str,int l,int r,boolean[][] dp) {
    if(l==r){
        return true;
    }
    if(l-r==1){
        if(str.charAt(l)==str.charAt(r)){
            return true;
        }
        else{
            return false;
        }
    }
    if(dp[l][r]!=false){
        return true;
    }
    boolean ans = count(str,l+1,r-1,dp) && str.charAt(l)==str.charAt(r);
    return dp[l][r]=ans;
}

}

hello @D18CRXN0014
u r computing dp again and again,
first compute dp table and then answer each query in O(1).

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.

I still have a doubt

Hey @D18CRXN0014 buddy
Welcome to the Coding Blocks family
Hope you’re enjoying your course
Yes please ask your doubt

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.