Test cases not passing

question - Chef and Chain
rating-1332
here we have to find the minimum number of characters to flip to get an alternating sequence of ‘+’ and ‘-’.
My approach is to check for consecutive same elements in the array and flip the next element incrementing count in the process
link to my solution- CodeChef: Practical coding for everyone

The problem with your code is that you are only flipping symbols. You effectibly are finding a solution, but this code won’t find a minimal solution, which is required.

Say:

" + - - - - + - "

Your code will make 4 flips and will transform the string into:
" + - + - + - + "

The problem is that that’s not the minimal amount. The minimal is 3:

" - + - + - + - "

1 Like

thanks