Number of Pairs of Non-Intersecting Palindromic Substrings in a String

Revision en1, by vamaddur, 2017-09-23 18:04:48

Problem Link

My strategy is to compute the number of palindromic substrings from index 0 to index i in a prefix sum array, and then compute the number of palindromic substrings from i+1 to strlen(N)-1 in a suffix sum array. We can then sum the products of prefix[i]*suffix[i+1] and somehow account for overcounting to get our answer. My main issue is finding the number of palindromic substrings in O(N) time (O(N^2) is not feasible as N could be up to 10^5).

Is my method reasonable, and if so, how can I solve the subproblem of finding the number of palindromic substrings in a prefix?

Please help, and thanks in advance!

Tags palindromes, #strings

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English vamaddur 2017-09-23 18:04:48 741 Initial revision (published)