Remove Adjacent Almost-Equal Characters

You are given a 0-indexed string word.

In one operation, you can pick any index i of word and change word[i] to any lowercase English letter.

Return the minimum number of operations needed to remove all adjacent almost-equal characters from word.

Two characters a and b are almost-equal if a == b or a and b are adjacent in the alphabet.

Example 1
Inputword = "aaaaa"
Output2
We can change word into "acaca", which does not have any adjacent almost-equal characters, and it can be shown that 2 is the minimum number of operations needed.
Example 2
Inputword = "abddez"
Output2
We can change word into "ybdoez", which does not have any adjacent almost-equal characters, and it can be shown that 2 is the minimum number of operations needed.

Constraints

  • 1 <= word.length <= 100
  • word consists only of lowercase English letters.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate