100% Beats || Easy to Understand with Intuition and Approach || Linear Complexity and Constant Space
Intuition\n Describe your first thoughts on how to solve this problem. \nProblem straight forward tells us what we have to do, if we find any index such that it
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nProblem straight forward tells us what we have to do, if we find any index such that it\'s adjacent character is either equal or different by one from the current index\'s character then we have to change it.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe start traversing our string from $index = 1$, and we initialise the variable $count = 0$, if we find a index where $s[index - 1] = s[index]$ or $abs(s[index] - s[index - 1]) = 1$ then we increment the $count$ variable and jump 2 indexes as the previous one and current one and the one next to it have already been taken care of. If we do not find this condition then we simply increment the $index$.\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Please Upvote!\n![image.png](https://assets.leetcode.com/users/images/df44b72f-3410-4242-aafa-20d33e8fe1e7_1702280521.1919644.png)\n\n# Beats\n![image.png](https://assets.leetcode.com/users/images/04209e7a-5ef8-452d-b200-bc898ac4f930_1702280624.836791.png)\n\n\n# Code\n```\nclass Solution\n{\npublic:\n    int removeAlmostEqualCharacters(string word)\n    {\n        int count = 0, index = 1;\n        while (index < word.size())\n        {\n            if (word[index] == word[index - 1] || abs(word[index] - word[index - 1]) == 1)\n            {\n                count++;\n                index += 2;\n                continue;\n            }\n            index++;\n        }\n        return count;\n    }\n};\n```\n
['C++']