In the problem good string([https://mirror.codeforces.com/problemset/problem/1389/C]) I made two observations- 1. When n is odd then all characters are equal ~~~~~ 2. Else
s1 = s3 = ... = sn
~~~~~
s2 = s4 = ... = sn-1
~~~~~
It means the string is fixed by the first two starting characters. I iterated from 0 to 9 for the first two characters and found the count of positions-
- if i is odd and si != s1 or
- i is even and si != s2 ~~~~~
My answer is off by one in some test cases. I want to a small test string where I could find the reason.
If you are taking an alternating sequence then the length of the sequence must be even.
Eg: 59595
Here the alternating sequence is of length 5 but we need an even length if we are alternating so ans will be 4. But if you are taking all same chars then it can odd or even, no matter.
This may be the reason your answers are off by only 1.
My submission : Good String
I am pretty sure that if all the numbers are the same (i.e. aaaaa...), then it can have any length, odd or even. If the numbers are in alternating order (i.e. ababab...), then it HAS to be even.
This is my submission -> https://mirror.codeforces.com/contest/1389/submission/88384839
If you want it. Test this string out:
1233330985
The optimal answer is to remove everything except for the EVEN amount of 3's