✅ Beats 100% | Greedy is faster.
\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n All we need is to check if the difference between the characters is not greater 
![image.png](https://assets.leetcode.com/users/images/6a7ef574-693a-49fa-b4c4-6976d273e526_1703393816.130184.png)\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n* All we need is to check if the difference between the characters is not greater than 1\n* if true, just increment the counter, and go for the next character. \n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. initialize a counter in which we store the result with 0.\n2. iterate over the given string for i = 1 to length of the string. \n    1. if the current character is greater than the previous character alphabetically\n        1. check if the difference between the greater - smaller <= 1 (near close)\n            1. increment the ans\n            2. increment i to avoid redundant evaluations.\n    2. do exactly the same if the character was less, but the greater charachter will now be the previous one.\n3. return the result.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n1. O(N) , where n is the length of the given string. \n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n1. O(1) -> no auxilary space is needed.\n# Code\n```\n#pragma GCC optimize("O3")\n#pragma GCC optimize("Ofast", "inline", "ffast-math", "unroll-loops", "no-stack-protector")\n#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native", "f16c")\nstatic const auto DPSolver = []()\n{ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return \'c\'; }();\nclass Solution {\npublic:\n    int removeAlmostEqualCharacters(string word) {\n        DPSolver; \n        int ans = 0;\n        for(int i = 1;i<word.length();i++){\n            \n            if(word[i]>=word[i-1] && word[i]-word[i-1]<=1)\n            {\n                ans++;\n                i++;\n            }\n            else if(word[i]<word[i-1] && word[i-1]-word[i]<=1){\n                ans++;\n                i++;\n            }\n        }\n        return ans;\n    }\n};\n```
['String', 'Dynamic Programming', 'Greedy', 'C++']