O(N) TC & O(1) SC solution || easy and Intuitive || Explained
Intuition\nHere all we needed was how many such group (adjacent almost equal) are occuring & what is there size\n> once we have the size of such group we need c
# Intuition\nHere all we needed was how many such group (adjacent almost equal) are occuring & what is there size\n> once we have the size of such group we need count of replacement that can be calculated by an easy formula\nExamine the pattern\n\n> if group size is 2 we need 1 replacement -> 1\nif 3 we still need one which is middle element should be replaced -> 1\nsimilarly 4 alternate element should be replaced -> 2\nsame goes with 5 -> 2\n6 -> 3\n7 -> 3\n\nhence what we needed was group size/2 replacements.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n    public int removeAlmostEqualCharacters(String word) {\n        int ans = 0;\n        \n        int currAdj = 1;\n        for(int i = 1; i < word.length(); i++) {\n            if(Math.abs(word.charAt(i) - word.charAt(i-1)) <= 1) {\n                currAdj++;\n            } else{\n                ans += currAdj/2;\n                currAdj = 1;\n            }\n        }\n        \n        if(currAdj > 1) {\n            ans += currAdj/2;\n        }\n        return ans;\n    }\n}\n```
['Math', 'Greedy', 'Java']