🔥✅2 Approaches ||  DP(Memoization) + 🌟Greedy || 💯Clean Code
\n# Complexity\n\n- Time complexity:\nO(n)\n\n- Space complexity:\n- O(1) for Approach 1\n- O(n) for Approach 2\n\n\n# Code\n## Please Upvote if it helps\uD83E\
\n# Complexity\n```\n- Time complexity:\nO(n)\n\n- Space complexity:\n- O(1) for Approach 1\n- O(n) for Approach 2\n```\n\n# Code\n## Please Upvote if it helps\uD83E\uDD17\n# 1st Approach(GREEDY):-\n```\nclass Solution {\npublic:\n    int removeAlmostEqualCharacters(string word) {\n        int n = word.size(), ans = 0, cnt = 0;\n        for(int i = 0 ; i < n - 1 ; i++){\n            cnt++;\n            int diff = abs(word[i] - word[i + 1]);\n            if(diff > 1){\n                ans += cnt / 2;\n                cnt = 0;\n            }\n        }\n        cnt++;\n        ans += cnt / 2;\n        return ans;\n    }\n};\n```\n# 2nd Approach(DP):-\n```\nclass Solution {\npublic:\n    int dp[101];\n    int helper(int ind, int n, string& word){\n        if(ind >= n)\n            return 0;\n        if(dp[ind] != -1)\n            return dp[ind];\n        int mini = n;\n        int diff1 = abs(word[ind] - word[ind - 1]), diff2 = -1;\n        if(ind + 1 < n)\n            diff2 = abs(word[ind] - word[ind + 1]);\n        if(diff1 == 0 || diff1 == 1)\n            mini = min(mini , 1 + helper(ind + 2, n, word));\n        else{\n            if(diff2 == 0 || diff2 == 1){\n                mini = min(mini , 1 + helper(ind + 2, n, word));\n                mini = min(mini , helper(ind + 1, n, word));\n            }\n            else\n                mini = min(mini, helper(ind + 2, n, word));\n        }\n        return dp[ind] = mini;\n    }\n    \n    int removeAlmostEqualCharacters(string word) {\n        int n = word.size();\n        memset(dp, -1, sizeof(dp));\n        return helper(1, n , word);\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C++']