When we need to check whether a substring s[i..j] is a palindrome for all pairs of i, j, we can use the following solutions to reduce the time complexity from the brute force O(N^3) to O(N^2).
Rolling Hash
Calculate the hash in both directions and then compare the hash.