🔥BEATS 💯 % 🎯 |✨SUPER EASY BEGINNERS 👏
\n\n\n\n---\n\n# Intuition\nThe problem requires simulating transformations on character counts in a string over a specified number of steps. Each transformatio
![image.png](https://assets.leetcode.com/users/images/4ecfc8aa-335f-43ab-b20d-c73b4a4d02f1_1730018219.056606.png)\n\n\n\n---\n\n# Intuition\nThe problem requires simulating transformations on character counts in a string over a specified number of steps. Each transformation redistributes character counts according to the rules, and by iterating `t` times, we calculate the final count. The modulo operation ensures we avoid overflow due to the potentially large counts.\n\n# Approach\n1. Initialize an array `cnt` to store the frequency of each character in the string.\n2. For each transformation, use a temporary array `tmp` to apply the rules:\n   - For characters `a` to `y`, increment the next character\'s position.\n   - For `z`, increment both `a` and `b`.\n3. Update `cnt` with `tmp` values after each transformation.\n4. Sum all values in `cnt` to get the final length after transformations.\n\n# Complexity\n- **Time Complexity**: \\(O(t \\times 26)\\) since we process each transformation across all 26 alphabet positions.\n- **Space Complexity**: \\(O(26)\\), as we only store counts for each letter.\n\n---\n\n# Code\n\n\n```dart []\nclass Solution {\n  int lengthAfterTransformations(String s, int t) {\n    const int MOD = 1000000007;\n    List<int> cnt = List.filled(26, 0);\n\n    // Count occurrences of each character in the string\n    for (int i = 0; i < s.length; i++) {\n      cnt[s.codeUnitAt(i) - \'a\'.codeUnitAt(0)]++;\n    }\n\n    // Perform transformations\n    for (int j = 0; j < t; j++) {\n      List<int> tmp = List.filled(26, 0);\n      for (int i = 0; i < 26; i++) {\n        if (i == 25) {\n          tmp[0] = (tmp[0] + cnt[i]) % MOD;\n          tmp[1] = (tmp[1] + cnt[i]) % MOD;\n        } else {\n          tmp[i + 1] = (tmp[i + 1] + cnt[i]) % MOD;\n        }\n      }\n      cnt = tmp;\n    }\n\n    // Calculate final length\n    int len = 0;\n    for (int c in cnt) {\n      len = (len + c) % MOD;\n    }\n\n    return len;\n  }\n}\n```\n\n\n```java []\nclass Solution {\n    public int lengthAfterTransformations(String s, int t) {\n        final int MOD = 1000000007;\n        int[] cnt = new int[26];\n        \n        for (char c : s.toCharArray()) {\n            cnt[c - \'a\']++;\n        }\n\n        for (int j = 0; j < t; j++) {\n            int[] tmp = new int[26];\n            for (int i = 0; i < 26; i++) {\n                if (i == 25) {\n                    tmp[0] = (tmp[0] + cnt[i]) % MOD;\n                    tmp[1] = (tmp[1] + cnt[i]) % MOD;\n                } else {\n                    tmp[i + 1] = (tmp[i + 1] + cnt[i]) % MOD;\n                }\n            }\n            cnt = tmp;\n        }\n\n        int len = 0;\n        for (int c : cnt) {\n            len = (len + c) % MOD;\n        }\n\n        return len;\n    }\n}\n```\n\n\n```javascript []\nvar lengthAfterTransformations = function(s, t) {\n    const MOD = 1000000007;\n    let cnt = Array(26).fill(0);\n    \n    for (let char of s) {\n        cnt[char.charCodeAt(0) - \'a\'.charCodeAt(0)]++;\n    }\n\n    for (let j = 0; j < t; j++) {\n        let tmp = Array(26).fill(0);\n        for (let i = 0; i < 26; i++) {\n            if (i === 25) {\n                tmp[0] = (tmp[0] + cnt[i]) % MOD;\n                tmp[1] = (tmp[1] + cnt[i]) % MOD;\n            } else {\n                tmp[i + 1] = (tmp[i + 1] + cnt[i]) % MOD;\n            }\n        }\n        cnt = tmp;\n    }\n\n    return cnt.reduce((sum, val) => (sum + val) % MOD, 0);\n};\n```\n\n\n```python []\nclass Solution:\n    def lengthAfterTransformations(self, s: str, t: int) -> int:\n        MOD = 1000000007\n        cnt = [0] * 26\n        \n        for char in s:\n            cnt[ord(char) - ord(\'a\')] += 1\n\n        for _ in range(t):\n            tmp = [0] * 26\n            for i in range(26):\n                if i == 25:\n                    tmp[0] = (tmp[0] + cnt[i]) % MOD\n                    tmp[1] = (tmp[1] + cnt[i]) % MOD\n                else:\n                    tmp[i + 1] = (tmp[i + 1] + cnt[i]) % MOD\n            cnt = tmp\n\n        return sum(cnt) % MOD\n```\n\n\n```cpp []\n#include <vector>\n#include <string>\n\nclass Solution {\npublic:\n    int lengthAfterTransformations(std::string s, int t) {\n        const int MOD = 1000000007;\n        std::vector<int> cnt(26, 0);\n\n        for (char c : s) {\n            cnt[c - \'a\']++;\n        }\n\n        for (int j = 0; j < t; j++) {\n            std::vector<int> tmp(26, 0);\n            for (int i = 0; i < 26; i++) {\n                if (i == 25) {\n                    tmp[0] = (tmp[0] + cnt[i]) % MOD;\n                    tmp[1] = (tmp[1] + cnt[i]) % MOD;\n                } else {\n                    tmp[i + 1] = (tmp[i + 1] + cnt[i]) % MOD;\n                }\n            }\n            cnt = tmp;\n        }\n\n        int len = 0;\n        for (int c : cnt) {\n            len = (len + c) % MOD;\n        }\n\n        return len;\n    }\n};\n```\n\n\n```go []\npackage main\n\nconst MOD int = 1000000007\n\nfunc lengthAfterTransformations(s string, t int) int {\n    cnt := make([]int, 26)\n\n    for _, char := range s {\n        cnt[char-\'a\']++\n    }\n\n    for j := 0; j < t; j++ {\n        tmp := make([]int, 26)\n        for i := 0; i < 26; i++ {\n            if i == 25 {\n                tmp[0] = (tmp[0] + cnt[i]) % MOD\n                tmp[1] = (tmp[1] + cnt[i]) % MOD\n            } else {\n                tmp[i+1] = (tmp[i+1] + cnt[i]) % MOD\n            }\n        }\n        cnt = tmp\n    }\n\n    len := 0\n    for _, c := range cnt {\n        len = (len + c) % MOD\n    }\n\n    return len\n}\n```\n\nThese solutions simulate the character transformations step-by-step and compute the total character length after `t` transformations. Each implementation efficiently handles large counts using modular arithmetic.\n\n---\n\n![image.png](https://assets.leetcode.com/users/images/d81a7cee-fa73-41a2-82dc-65bf475d960c_1722267693.3902693.png) {:style=\'width:250px\'}\n\n
['C', 'C++', 'Java', 'Go', 'Python3', 'JavaScript', 'Dart']