CAN ANYONE EXPLAIN HOW THE ANSWER OF THE LAST TEST CASE OF “PALINDROME” IS COMING 213?

The last two slashes of baba//aaa/ab// must be replaced by ab -> baba//aaa/abab. The middle slash of baba//aaa/abab must be a -> baba/aaaa/abab. The two remaining slashes can be replaced by a’s or b’s, but b has the lower cost, so it is used -> bababaaaababab. In summary, we replaced the 5 slashes by two a’s and three b’s. So, the answer is 2x72+3x23=213.

1 Like

for the given sample that is **baba//aaa/ab//**, the comparisons are:

```
left right condition cost action
b / 4 23 place 'b' at s
a / 1 72 place 'a' at s
b b
a a
/ / 5 twice 23 place 'b' at s and s[right]
/ a 2 72 place 'a' at s[right]
a a
```

hence the total cost comes out to be 213.

Which question on Palindromes are you referring to???