✅☑[C++/Java/Python/JavaScript] || Beats 100% || EXPLAINED🔥
PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n(Also explained in the code)\n\n\n1. The code uses a check function to verify if characters at two position
# PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n**(Also explained in the code)**\n\n\n1. The code uses a `check` function to verify if characters at two positions are equal or almost equal.\n1. `removeAlmostEqualCharacters` iterates through the string, counting instances where characters are equal or almost equal.\n\n# Complexity\n- *Time complexity:*\n   $$O(n)$$\n    \n\n- *Space complexity:*\n   $$O(1)$$\n    \n\n\n# Code\n```C++ []\nclass Solution {\nprivate:\n    // Function to check if the characters are equal or almost equal\n    bool check(char x, char y) {\n        // If characters are equal or adjacent in the alphabet, return true\n        if (x == y)\n            return true;\n        if (x + 1 == y || x == y + 1)\n            return true;\n        return false;\n    }\n\npublic:\n    int removeAlmostEqualCharacters(string word) {\n        int n = word.length(); // Length of the given word\n        \n        int ans = 0; // Initialize the answer counter\n        int k = 0; // Initialize pointer for iteration\n        \n        while (k < n - 1) {\n            // Check if characters at position k and k+1 are equal or almost equal\n            if (check(word[k], word[k + 1])) {\n                ans++; // Increment the counter for almost equal characters\n                k++; // Move to the next character after handling the pair\n            }\n            k++; // Move to the next character for comparison\n        }\n        \n        return ans; // Return the total count of almost equal characters\n    }\n};\n\n\n\n```\n```C []\n// Function to check if the characters are equal or almost equal\nbool check(char x, char y) {\n    // If characters are equal or adjacent in the alphabet, return true\n    if (x == y)\n        return true;\n    if (x + 1 == y || x == y + 1)\n        return true;\n    return false;\n}\n\nint removeAlmostEqualCharacters(char word[]) {\n    int n = strlen(word); // Length of the given word\n    \n    int ans = 0; // Initialize the answer counter\n    int k = 0; // Initialize pointer for iteration\n    \n    while (k < n - 1) {\n        // Check if characters at position k and k+1 are equal or almost equal\n        if (check(word[k], word[k + 1])) {\n            ans++; // Increment the counter for almost equal characters\n            k++; // Move to the next character after handling the pair\n        }\n        k++; // Move to the next character for comparison\n    }\n    \n    return ans; // Return the total count of almost equal characters\n}\n\n\n\n```\n```Java []\nclass Solution {\n    private boolean check(char x, char y) {\n        if (x == y)\n            return true;\n        if (x + 1 == y || x == y + 1)\n            return true;\n        return false;\n    }\n\n    public int removeAlmostEqualCharacters(String word) {\n        int n = word.length();\n        int ans = 0;\n        int k = 0;\n        \n        while (k < n - 1) {\n            if (check(word.charAt(k), word.charAt(k + 1))) {\n                ans++;\n                k++;\n            }\n            k++;\n        }\n        \n        return ans;\n    }\n}\n\n\n\n```\n```python3 []\nclass Solution:\n    def check(self, x, y):\n        if x == y:\n            return True\n        if x + 1 == ord(y) or x == ord(y) + 1:\n            return True\n        return False\n\n    def removeAlmostEqualCharacters(self, word: str) -> int:\n        n = len(word)\n        ans = 0\n        k = 0\n        \n        while k < n - 1:\n            if self.check(ord(word[k]), ord(word[k + 1])):\n                ans += 1\n                k += 1\n            k += 1\n        \n        return ans\n\n\n\n```\n```javascript []\nfunction removeAlmostEqualCharacters(word) {\n    const n = word.length; // Length of the given word\n    \n    let ans = 0; // Initialize the answer counter\n    let k = 0; // Initialize pointer for iteration\n    \n    while (k < n - 1) {\n        // Check if characters at position k and k+1 are equal or almost equal\n        if (word[k] === word[k + 1] || Math.abs(word[k].charCodeAt(0) - word[k + 1].charCodeAt(0)) === 1) {\n            ans++; // Increment the counter for almost equal characters\n            k++; // Move to the next character after handling the pair\n        }\n        k++; // Move to the next character for comparison\n    }\n    \n    return ans; // Return the total count of almost equal characters\n}\n\n\n\n```\n\n---\n\n\n\n# PLEASE UPVOTE IF IT HELPED\n\n---\n---\n\n\n---
['String', 'C', 'C++', 'Java', 'Python3', 'JavaScript']