PYTHON TigProg's solution with notes.
ALL CREDIT GOES TO: TigProg\'s solution\n\n\n# Code\npython3 []\n# Copying TigProg\'s solution:\n\n#  https://leetcode.com/problems/total-characters-in-string-a
# ALL CREDIT GOES TO: [TigProg\'s solution](https://leetcode.com/problems/total-characters-in-string-after-transformations-i/solutions/5974729/simple-python3-solution-simulation-with-recursion)\n\n\n# Code\n```python3 []\n# Copying TigProg\'s solution:\n\n#  https://leetcode.com/problems/total-characters-in-string-after-transformations-i/solutions/5974729/simple-python3-solution-simulation-with-recursion\n\nfrom collections import Counter\n\nimport functools\n\nclass Solution:\n\n    LIMIT = 1_000_000_007\n\n    def lengthAfterTransformations(self, s: str, t: int) -> int:\n        # Each character will transform in the same way.\n        # We can count how many times they appear, and save redundant operations.\n        char_to_costs = Counter(s)\n\n        total_cost = 0\n\n        for each_char, each_frequency in char_to_costs.items():\n            iteration_cost = self._simulated_transform(each_char, t)\n            all_occurrences_cost = iteration_cost * each_frequency\n            total_cost += all_occurrences_cost\n            total_cost = total_cost % self.LIMIT\n\n        return total_cost\n\n    @functools.cache\n    def _simulated_transform(self, char, t):\n        """Simulates the lifetime cost of transforming a single char.\n\n        Args:\n            char: Target char.\n            t: The total number of transformation operations to perform.\n\n        Returns:\n            The cost of transforming char t times.\n        """\n\n        char_index = ord(char) - ord(\'a\')  # Index of char from \'a\'\n        shift = 26 - char_index # \n        t -= shift\n\n        if t < 0:  # Shift successful, next character replaced.\n            return 1\n        # Else... \n\n        # Character is \'z\' and must be replaced with \'ab\'\n        a_cost = self._simulated_transform(\'a\', t)\n        b_cost = self._simulated_transform(\'b\', t)\n        total_cost = (a_cost + b_cost) % self.LIMIT\n        return total_cost\n    \n```
['Python3']