Simple Java Solution || O(N) ⭐⭐⭐
Time complexity:O(n)\n\n# Code\n\nclass Solution {\n    public int removeAlmostEqualCharacters(String word) {\n         \n        StringBuilder str = new String
- Time complexity:O(n)\n\n# Code\n```\nclass Solution {\n    public int removeAlmostEqualCharacters(String word) {\n         \n        StringBuilder str = new StringBuilder("");\n        int n= word.length();\n        str.append(word.charAt(0));\n        \n        for(int i=1;i<n;i++)\n        {\n            char curr= word.charAt(i);\n            char prev= str.charAt(i-1);\n            if(prev==\'#\')str.append(curr);\n            else{\n                  if(prev!=\'#\' &&  Math.abs(curr-prev)!=1 && Math.abs(curr-prev)!=0) str.append(curr);\n                   else\n                        str.append("#");\n            }\n        }\n        int count=0;\n        for(int i=0;i<str.length();i++)\n        {\n          if(str.charAt(i)==\'#\') count++;\n        }\n        return count;\n        \n    }\n}\n```
['Java']