https://practice.geeksforgeeks.org/problems/count-of-palindromic-substrings-in-an-index-range/0/
thsi code shows wa on submission on geeks for geeks
plz make changes in my code and explain them…
dont provide link of editorial…
https://practice.geeksforgeeks.org/problems/count-of-palindromic-substrings-in-an-index-range/0/
thsi code shows wa on submission on geeks for geeks
plz make changes in my code and explain them…
dont provide link of editorial…
ok, I’ll try and explain this to you.
for any character to be included in a palindromic substring, it has to be the following:
dp[i][j] will be addition of number
of palindromes from i to j-1 and i+1
to j subtracting palindromes from i+1
to j-1 (as counted twice) plus 1 if
str(i..j) is also a palindrome
i have coded the problem using the approach where we check for strings of all sizes using tabulated manner only but i am getting wrong ans i cant figure out why so plz make changes in my code so that i get correct ans on gfg on submission…
make changes in my code…
i have tried to count palindromic substring in substring of this string geneerated using the index given in ques…this is what i have done…
actually there is also a problem to count palindromic substrings in a given string so i just implemented that here …so correction of code will also help me to corrct that code as well…plz reply at the earliest…
in your code:
for(int i=3;i<=n;i++)
{
for(int j=0;j<n-i+1;j++)
{
int k=i+j-1;
if(dp[j+1][k-1]==1&&a[j]==a[k])
{
dp[j][k]=1;
count++;
}
}
}
this part is a bit unclear, cna you walk me through?
I mean it does not align with approach or the question
i have tried to count substring of length 3 or more length whether they are palindrmic or not
i have looked at first and last char and if same then i have looked at inner characters(1 forward and 1 backward from start and end ) dp table if it is 1 then it is a palindrome
Have you tried drawing the DP table on paper once?
Draw it once, and you will notice one thing. MISSING INDICES. which is equivalent to missing combinations
and in cases of odd and even
in odd, this still might work, since xyx is a palindrome
but for even when u check for xyyx at either y it will give false even for x when u check inside it will return false, since by remove x from yyx the resultant is not palindrome
at each step u need to recheck
in xyyx i will remove both x from front and end (sice they are same char and match) and then check for inner string which is left yy whether it is a palindrome or not…
also when i run the code for xyyx it gives ans as 6
x
y
x
x
xyyx
and yy
which is correct
why arent u replying???plz reply its been days
Why aren’t you replying properly plz clear the doubt properly ??
Or else I willl have to report this