thierrypin
BAN USER
Comments (3)
Reputation 80
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Would it be Ω(N) and O(N^2)?
It would be better than the "traditional" Θ(N^2)...
Comment hidden because of low score. Click to expand.
8
of 8 vote
I made a recursive algorithm
int kpal(int k, char *str, int i, int j)
{
if (k < 0)
return 0;
else if (i == j)
return 1;
// Verify if it's a palindrom
while (i < j)
{
// If it's not, call the function recursively
if (str[i] != str[j])
{
int res = kpal(k-1, str, i+1, j);
if (!res)
res = kpal(k-1, str, i, j-1);
if (!res)
return 0;
else
return 1;
}
++i;--j;
}
return 1;
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
But it's not Ω(N), because you have to go through the sum array after running the original array.
- thierrypin September 05, 2013