Minimum Changes for Distinct Adjacent Characters
Problem statement
You are given a string s. In one operation, you may choose any position and replace its character with any lowercase English letter.
Return the minimum number of operations needed so that no two adjacent characters in s are equal.
Function
minimumChangesForDistinctAdjacentCharacters(s: String) → intExamples
Example 1
s = "aaab"return = 1Change the middle 'a' to 'b', producing "abab".
Example 2
s = "aaaaa"return = 2Two replacements are sufficient, for example to obtain "ababa", and one replacement cannot break all four equal adjacencies.
Example 3
s = "abcde"return = 0Every adjacent pair already contains different characters.
Constraints
1 <= s.length <= 200000.scontains only lowercase English letters.