You are given an array words of strings. Each string consists only of lowercase English letters. In one operation, you may change any character in a string to any other lowercase letter. After performing some number of such operations on a string, the string must contain no two adjacent equal characters.
For each string in words, determine the minimum number of character changes needed to achieve this property. Return an integer array where the -th element is the answer for words[i].
Implement the function minimalOperations with the following signature:
public static List<Integer> minimalOperations(List<String> words)
Example 1:
Input: words = ["book", "keeper", "break"]
Output: [1, 1, 0]
Explanation:
"book" has the adjacent equal pair "oo" – one change is sufficient (e.g., change one 'o' to 'k').
"keeper" has the adjacent equal pair "ee" – one change makes it valid.
"break" already has no identical neighbours, so zero changes.
Example 2:
Input: words = ["abc", "aa", "abba"]
Output: [0, 1, 1]
Explanation:
"abc" requires no changes.
"aa" requires exactly one change (e.g., change the second 'a' to 'b').
"abba" contains adjacent 'b's – one change, for example changing the first 'b' to 'c', makes the string valid.
Constraints:
'a' to 'z'.