Minimum Changes for a Beautiful String
Problem statement
A lowercase string is beautiful when the absolute alphabet-index difference between every pair of adjacent characters is greater than 1. Equal letters and consecutive letters are therefore invalid neighbors; a and z are not consecutive.
In one operation, choose any position and replace its character with any lowercase English letter. Return the minimum number of operations needed to make s beautiful.
Function
getMinimumOperationCount(s: String) → intExamples
Example 1
s = "bddje"return = 1Changing the second d to f gives bdfje, whose adjacent differences are all greater than one.
Example 2
s = "acaz"return = 0Every adjacent alphabet-index difference is already at least two.
Constraints
1 <= s.length <= 100000.scontains only lowercase English letters.
Source note: The source image is a source-neutral excerpt of the author-reported prompt.