package com.xxx.amp.magenta.livecodebench.solution;

public class RemoveAdjacentSolution {
    public int removeAlmostEqualCharacters(String word) {
        int operations = 0;
        char[] chars = word.toCharArray();
        
        for (int i = 1; i < chars.length; i++) {
            if (areAlmostEqual(chars[i], chars[i - 1])) {
                operations++;
                // Change the current character to a different one
                chars[i] = getDifferentChar(chars[i - 1], chars[i]);
            }
        }
        
        return operations;
    }
    
    private boolean areAlmostEqual(char a, char b) {
        return a == b || Math.abs(a - b) == 1;
    }
    
    private char getDifferentChar(char exclude1, char exclude2) {
        for (char c = 'a'; c <= 'z'; c++) {
            if (c != exclude1 && c != exclude2) {
                return c;
            }
        }
        return 'a'; // This should never be reached since we always have options
    }
}
