(30ms)Frequencies and cycle of condition fulfillment.
Approach\nThe idea is here:\nhttps://leetcode.com/problems/total-characters-in-string-after-transformations-i/solutions/5972951/simple-and-clean-java-solution-o
# Approach\nThe idea is here:\nhttps://leetcode.com/problems/total-characters-in-string-after-transformations-i/solutions/5972951/simple-and-clean-java-solution-o-26-t\n# Complexity\n![image.png](https://assets.leetcode.com/users/images/9878cabd-9d7e-416d-a574-7cbc0d448f9e_1730053080.9149644.png)\n# Code\n```kotlin []\nclass Solution {\n    fun lengthAfterTransformations(s: String, t: Int): Int {\n        val alpha = IntArray(26)\n        for (ch in s) alpha[ch - \'a\']++\n        repeat(t) {\n            val tmp = alpha[25]\n            for (j in 25 downTo 1) alpha[j] = alpha[j-1]\n            alpha[0] = tmp\n            alpha[1] = (alpha[1] + tmp) % mod\n        }\n\n        var len = 0\n        for (a in alpha) len = (len + a) % mod\n        return len\n    }\n    companion object {\n        val mod = 1_000_000_007\n    }    \n}\n\n```\n# OR\n![image.png](https://assets.leetcode.com/users/images/a0459a99-e308-4f32-a818-5082c77534b6_1730139379.125154.png)\n```\nclass Solution {\n    fun lengthAfterTransformations(s: String, t: Int): Int {\n        val alphaA = IntArray(26)\n        val alpha = LinkedList<Int>()\n\n        for (ch in s) alphaA[ch - \'a\']++\n        for (N in alphaA) alpha.add(N)\n\n        repeat(t) {\n            val tmp = alpha.pollLast()\n            val tmp1 = alpha.pollFirst()\n            \n            alpha.addFirst((tmp1 + tmp) % mod) \n            alpha.addFirst(tmp) \n        }\n\n        var len = 0\n        for (a in alpha) len = (len + a) % mod\n        return len\n    }\n    companion object {\n        val mod = 1_000_000_007\n    }    \n}\n```\n# Or even so:\n![image.png](https://assets.leetcode.com/users/images/4e543d5a-cf3f-47c6-9e36-4070623058c1_1730139417.5870593.png)\n```\nclass Solution {\n    fun lengthAfterTransformations(s: String, t: Int): Int {\n        var start = 100_000\n        for (i in start until start+26) alpha[i]=0\n        for (ch in s) alpha[ch - \'a\' + start]++\n        repeat(t) {\n            start--\n            val temp = alpha[start+26]\n            alpha[start+1] = (alpha[start+1] + temp) % mod\n            alpha[start] = temp\n        }\n        var len = 0L\n        for (i in start until start+26) len += alpha[i]\n        return (len % mod).toInt()\n    }\n    companion object {\n        val mod = 1_000_000_007\n        val alpha = IntArray(100_026)\n    }\n\n}\n```
['Kotlin']