You are given a string s, and your task is to find and return the total number of palindromic substrings present in the string. A substring is considered palindromic if it reads the same forwards and backwards. You need to count all possible palindromic substrings, including single-character substrings and multi-character substrings. The goal is to determine the total count of such substrings efficiently, given the constraints on the length of the string.
I attempted a brute-force approach by generating all possible substrings of the given string and checking each one to see if it is a palindrome.
I expected to count all palindromic substrings correctly but found that the brute-force approach could be inefficient, especially for longer strings. An efficient solution should count all palindromic substrings in optimal time, ideally avoiding redundant checks and reducing unnecessary computations.
A rodrigo_13 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3