Beats 100%. Easy to understand for beginners.
IntuitionKeep track if last character is almost equal to current char.ApproachComplexity
Time complexity:
O(n)
Space complexity:
Code

# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
![image.png](https://assets.leetcode.com/users/images/0d97c502-36f7-43e5-a0ea-1c5881a614c5_1737968250.0994043.png)

Keep track if last character is almost equal to current char.
# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    static int solutionII(String s) {
        StringBuilder sb = new StringBuilder();
        int ans = 0;
// Intialize a StringBuilder sb and int ans.
        sb.append(s.charAt(0));
// Add first character of word to sb.
        for (int i = 1; i < s.length(); i++) {
// Check if current char is almost equal to last char.
            if (Math.abs(s.charAt(i) - sb.charAt(i - 1)) > 1) {
                sb.append(s.charAt(i));
// Add current char to sb if not equal.
            } else {
                sb.append('0');
                ans++;
// Add any non-alphabetic char to sb if not equal.
// Increase ans by one.
            }
        }
        return ans;
    }

    public int removeAlmostEqualCharacters(String word) {
        return solutionII(word);
    }
}
```
['String', 'Counting', 'Java']