Get Minimum Operation Count
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.
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
1Example 1
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=1and changes[i]to 'z',sbecomes "azdde". - Choose
i=3and changes[i]to 'k',sbecomes "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.
Constraints
Limits and guarantees your solution can rely on.
- 2 ≤ |
s| ≤ 10^5 - The string
scontains only lowercase English letters.