### Hamim99's blog

By Hamim99, history, 2 months ago, ,

Need idea for this problem. Any algorithm necessery for solving this problem? Problem link:https://www.hackerrank.com/contests/save-our-country/challenges/b-palindrome-and-virus-name

• -4

 » 2 months ago, # | ← Rev. 2 →   +3 Note that for each index $i$, you would have counted for the previous iteration all the palindrome substrings $[l,i-1]$, where $l \leq i-1$, ending at index $i-1$. You can keep a list of the starting index of each palindrome substring in each iteration. Initially, this list should be empty, and it should be updated as follows. A palindrome $[l,i-1]$ counted in the previous iteration should be expanded in the $i$-th iteration to $[l-1,i]$ if $l > 1$ and $S[l-1] = S[i]$. A 2-letter palindrome $[i-1,i]$ should be added to the updated list if $i > 1$ and $S[i-1] = S[i]$. A 1-letter plaindrome $[i,i]$ should be added to the updated list. The answer in the $i$-th iteration should be the size of the updated list.
•  » » 2 months ago, # ^ |   0 Can you give me solution of this problem?
•  » » » 2 months ago, # ^ | ← Rev. 2 →   0 The previous comment should be a valid solution to the problem. Do you mean sharing with you the submitted code?
•  » » » » 2 months ago, # ^ |   0 Yes brother.If you have submitted code.
•  » » » » » 2 months ago, # ^ | ← Rev. 3 →   0
•  » » 2 months ago, # ^ |   0 Thanks.
•  » » » 2 months ago, # ^ |   +4 With pleasure.
 » 2 months ago, # |   +4 Please, see here.