Quote:
But it's hard to find as in above case. Any thoughts ?
Don't try to find a magic trick, for such a problem, go brute force.
Brute force is to try every possibilities.
for any possible position of s2 in s1
reset changes counter
do necessary changes to have s2 in s1
do necessary changes to make s1 a palindrome (without changing the place holding s2)
if changes is better than previous tries, set the new minimum.
[update]
Quote:
How do you manage that 'any possible position of s2 in s1' ?
With input test="abcdefggfedcba" , sub_string="ifg"
for any possible position of s2 in s1
gives
ifgdefggfedcba
aifgefggfedcba
abifgfggfedcba
abcifgggfedcba
abcdifggfedcba
abcdeifgfedcba
abcdefifgedcba
abcdefgifgdcba
abcdefggifgcba
abcdefggfifgba
abcdefggfeifga
abcdefggfedifg
Quote:
If length of sub_string is very long and then most of time consumed i checking what portion of sub_string exists. correct ? Any efficient way ? What could be the solution ?
There is no magic, if there is a better way, you need a good knowledge of the problem, and experiment different solutions and see what works best.
What is best solution for this
test="abcfgfaba" , sub_string="ifg"
test="abcfgfaba" , sub_string="gfi"