Python - simple solution with detailed explanation (beats 100%)
Please upvote if you like my solution \u263A\uFE0F\n\n# Base assumptions:\n\nLet\u2019s take the word "xyz". Since the difference between \u2018x\u2019 and \u20
Please upvote if you like my solution \u263A\uFE0F\n\n# Base assumptions:\n\nLet\u2019s take the word "xyz". Since the difference between \u2018x\u2019 and \u2018y\u2019 is 1, we have to change either \u2018x\u2019 or \u2018y\u2019. The difference between \u2018y\u2019 and \u2018z\u2019 is also 1, so we already know that we will also have to change either \u2018y\u2019 and \u2018z\u2019. Since we want to make as little changes as possible, we will change \u2018y\u2019 in such a way that we neither have to change \u2018x\u2019 nor \u2018z\u2019. So we could change \u2018y\u2019 to any letter between \u2018a\u2019 and \u2018v\u2019.\n\nOne thing to notice here: if we have a word of 3 letters, it is always possible to change the middle letter in such a way that the difference to the other two letters is more than 1. \n\n# Conclusions:\n1.\tWe don\u2019t need to calculate what letter we are going to change the middle letter to. Because we don\u2019t have to return the actual word, we only have to return the number of transactions. So, it\u2019s enough to keep track of the fact that we would have to make a transaction.\n2.\tIf we have to change the middle letter in a word of 3 letters, we know that we don\u2019t have to make any changes to the 3rd letter because we can change the middle letter in such a way that the difference to the 3rd letter is also more than 1. In case we have a word with more than 3 letters, what this means for us is that we can skip one letter in the algorithm every time we hypothetically change a letter. I say hypothetically because we don\u2019t actually perform the calculation for performance reasons.\n\n# My algorithm:\n\n**1.**\tIterate over each letter in the word (skip the first letter)\n\n**2.**\tCheck if we have to make any changes to the current letter, which is the case if the difference to the previous letter is 1 or 0 <br>\n    **2.1**\tIf the difference is 1 or 0, then we hypothetically change the current letter to any letter so that the difference to the previous and following letter is more than 1. Since we already know that the difference to the next letter is going to be more than 1 we can skip the next iteration <br>\n    **2.2** Otherwise we move forward to the next letter\n\n\n# Performance\nTime complexity: O(n)\nSpace complexity: O(1)\n\n# Code\n```\nclass Solution:\n    def removeAlmostEqualCharacters(self, word: str) -> int:\n        res = 0\n        skip = False\n        for i in range(1,len(word)):\n            diff = ord(word[i])-ord(word[i-1])\n            if not skip and -1<=diff<=1:\n                res+=1\n                skip = True\n            else:\n                skip = False\n        return res\n\n```
['Python', 'Python3']