A string is beautiful if no two adjacent characters are either
The following operations can be performed on a string, s
.
i
(0 β€ i
< |s
|) and change s[i]
to any lowercase English letter.Find the minimum number of operations required to make the string beautiful.
Function Description
Complete the function getMinimumOperationCount
in the editor below.
getMinimumOperationCount
has the following parameter:
s
: a string
Returns
int
: the minimum number of operations required to make s
beautiful
Example 1:
Input: s = "abdde"
Output: 2
Explanation:String
s
is not beautiful because:
- 'dd' violates constraint 1, no two adjacent characters are the same.
- 'ab' and 'de' violate constraint 2, no two adjacent characters are adjacent in the alphabet.
The string can be converted into a beautiful string after 2 operations. One solution is below:
- Choose
i=1
and changes[i]
to 'z',s
becomes "azdde".- Choose
i=3
and changes[i]
to 'k',s
becomes "azdke" which is beautiful.Note: There are many other solutions such as "ardze", "axdke", etc.
It can be shown that 2 is the minimum number of operations required so return 2.
- 2 β€ |
s
| β€ 10^5 - The string
s
contains only lowercase English letters.

input:
output: