Simple Greedy Approach in O(n) time complexity
Objective: Count the occurrences of nearly equal consecutive characters in a given string.\n- Approach:\n  - Iterate through the string, comparing adjacent char
- **Objective**: Count the occurrences of nearly equal consecutive characters in a given string.\n- **Approach**:\n  - Iterate through the string, comparing adjacent characters.\n  - Increment the count when the absolute difference between characters is 0 or 1.\n  - Skip the next character to avoid double-counting.\n- **Implementation**:\n  - Use `abs(word[i+1] - word[i]) <= 1` as the condition for near equality.\n  - Return the final count as the result.\n\n# Code\n```\nclass Solution {\npublic:\n    int removeAlmostEqualCharacters(string word) {\n        int n=word.length();\n        int result=0;\n        for(int i=0; i<n; i++){\n            if(abs(word[i+1]-word[i]) <= 1){\n                result++;\n                i++;\n            }\n        }\n        return result;\n    }\n};\n```
['Greedy', 'C++']