DP Solution || From (Recursion) TLE to (DP) O(N)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\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```cpp []\nRECURSION(TLE)\n\nclass Solution {\npublic:\n    int solve(string word,int n,int index,int &ans){\n        if(index>=n)return 0;\n\n        int include=0;\n        if(index+1 != n &&  (abs(word[index]-word[index+1])<=1)){\n            include=1+solve(word,n,index+2,ans);\n        }\n        int exclude=solve(word,n,index+1,ans);\n        ans=max(include,exclude);\n        return ans;\n    }\n    int removeAlmostEqualCharacters(string word) {\n        \n        int ans=0;\n        int n=word.size();\n        solve(word,n,0,ans);\n        return ans;\n    }\n};\n\nRECURSION + MEMOIZATION\nclass Solution {\npublic:\n    int solve(string word,int n,int index,int &ans,vector<int>&dp){\n        if(index>=n)return 0;\n        if(dp[index]!=-1)return dp[index];\n        int include=0;\n        if(index+1 != n &&  (abs(word[index]-word[index+1])<=1)){\n            include=1+solve(word,n,index+2,ans,dp);\n        }\n        int exclude=solve(word,n,index+1,ans,dp);\n        \n        return dp[index]=max(include,exclude);\n    }\n    int removeAlmostEqualCharacters(string word) {\n        \n        int ans=0;\n        int n=word.size();\n        vector<int>dp(n+1,-1);\n        return solve(word,n,0,ans,dp);\n    }\n};\n\n\nBOTTOM-UP DP\nclass Solution {\npublic:\n    \n    int removeAlmostEqualCharacters(string word) {\n        int n=word.size();\n        vector<int>dp(n+1,0);\n        \n        for(int i=n-2;i>=0;i--){\n            int include=0;\n             if(i+1 != n &&  (abs(word[i]-word[i+1])<=1)){\n                include=1+dp[i+2];\n                }\n            int exclude=dp[i+1];\n            dp[i]=max(include,exclude);\n        }        \n    \n        return dp[0];\n    }\n};\n\nSPACE OPTIMZATION\n\nclass Solution {\npublic:\n    \n    int removeAlmostEqualCharacters(string word) {\n        int n=word.size();\n        int next=0;\n        int curr=0;\n        \n        for(int i=n-2;i>=0;i--){\n            int include=0;\n             if(i+1 != n &&  (abs(word[i]-word[i+1])<=1)){\n                include=1+next;\n                }\n            int exclude=curr;\n            next=curr;\n            curr=max(include,exclude);\n        }        \n    \n        return curr;\n    }\n};\n```
['C++']