Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes399downloads
total-characters-in-string-after-transformations-ii.json73 linesDownload Raw Back to root
1{2  "id": 3630,3  "name": "total-characters-in-string-after-transformations-ii",4  "difficulty": "Hard",5  "link": "https://leetcode.com/problems/total-characters-in-string-after-transformations-ii/",6  "date": "2024-10-20",7  "task_description": "You are given a string `s` consisting of lowercase English letters, an integer `t` representing the number of **transformations** to perform, and an array `nums` of size 26. In one **transformation**, every character in `s` is replaced according to the following rules: Replace `s[i]` with the **next** `nums[s[i] - 'a']` consecutive characters in the alphabet. For example, if `s[i] = 'a'` and `nums[0] = 3`, the character `'a'` transforms into the next 3 consecutive characters ahead of it, which results in `\"bcd\"`. The transformation **wraps** around the alphabet if it exceeds `'z'`. For example, if `s[i] = 'y'` and `nums[24] = 3`, the character `'y'` transforms into the next 3 consecutive characters ahead of it, which results in `\"zab\"`. Return the length of the resulting string after **exactly** `t` transformations. Since the answer may be very large, return it **modulo** `109 + 7`. **Example 1:** **Input:** s = \"abcyy\", t = 2, nums = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2] **Output:** 7 **Explanation:** **First Transformation (t = 1):** `'a'` becomes `'b'` as `nums[0] == 1` `'b'` becomes `'c'` as `nums[1] == 1` `'c'` becomes `'d'` as `nums[2] == 1` `'y'` becomes `'z'` as `nums[24] == 1` `'y'` becomes `'z'` as `nums[24] == 1` String after the first transformation: `\"bcdzz\"` **Second Transformation (t = 2):** `'b'` becomes `'c'` as `nums[1] == 1` `'c'` becomes `'d'` as `nums[2] == 1` `'d'` becomes `'e'` as `nums[3] == 1` `'z'` becomes `'ab'` as `nums[25] == 2` `'z'` becomes `'ab'` as `nums[25] == 2` String after the second transformation: `\"cdeabab\"` **Final Length of the string:** The string is `\"cdeabab\"`, which has 7 characters. **Example 2:** **Input:** s = \"azbk\", t = 1, nums = [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2] **Output:** 8 **Explanation:** **First Transformation (t = 1):** `'a'` becomes `'bc'` as `nums[0] == 2` `'z'` becomes `'ab'` as `nums[25] == 2` `'b'` becomes `'cd'` as `nums[1] == 2` `'k'` becomes `'lm'` as `nums[10] == 2` String after the first transformation: `\"bcabcdlm\"` **Final Length of the string:** The string is `\"bcabcdlm\"`, which has 8 characters. **Constraints:** `1 <= s.length <= 105` `s` consists only of lowercase English letters. `1 <= t <= 109` `nums.length == 26` `1 <= nums[i] <= 25`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "s = \"abcyy\", t = 2, nums = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2]",12      "output": "7 "13    },14    {15      "label": "Example 2",16      "input": "s = \"azbk\", t = 1, nums = [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]",17      "output": "8 "18    }19  ],20  "constraints": [21    "Replace s[i] with the next nums[s[i] - 'a'] consecutive characters in the alphabet. For example, if s[i] = 'a' and nums[0] = 3, the character 'a' transforms into the next 3 consecutive characters ahead of it, which results in \"bcd\".",22    "The transformation wraps around the alphabet if it exceeds 'z'. For example, if s[i] = 'y' and nums[24] = 3, the character 'y' transforms into the next 3 consecutive characters ahead of it, which results in \"zab\".",23    "First Transformation (t = 1):\n\n'a' becomes 'b' as nums[0] == 1\n'b' becomes 'c' as nums[1] == 1\n'c' becomes 'd' as nums[2] == 1\n'y' becomes 'z' as nums[24] == 1\n'y' becomes 'z' as nums[24] == 1\nString after the first transformation: \"bcdzz\"",24    "'a' becomes 'b' as nums[0] == 1",25    "'b' becomes 'c' as nums[1] == 1",26    "'c' becomes 'd' as nums[2] == 1",27    "'y' becomes 'z' as nums[24] == 1",28    "'y' becomes 'z' as nums[24] == 1",29    "String after the first transformation: \"bcdzz\"",30    "Second Transformation (t = 2):\n\n'b' becomes 'c' as nums[1] == 1\n'c' becomes 'd' as nums[2] == 1\n'd' becomes 'e' as nums[3] == 1\n'z' becomes 'ab' as nums[25] == 2\n'z' becomes 'ab' as nums[25] == 2\nString after the second transformation: \"cdeabab\"",31    "'b' becomes 'c' as nums[1] == 1",32    "'c' becomes 'd' as nums[2] == 1",33    "'d' becomes 'e' as nums[3] == 1",34    "'z' becomes 'ab' as nums[25] == 2",35    "'z' becomes 'ab' as nums[25] == 2",36    "String after the second transformation: \"cdeabab\"",37    "Final Length of the string: The string is \"cdeabab\", which has 7 characters.",38    "'a' becomes 'b' as nums[0] == 1",39    "'b' becomes 'c' as nums[1] == 1",40    "'c' becomes 'd' as nums[2] == 1",41    "'y' becomes 'z' as nums[24] == 1",42    "'y' becomes 'z' as nums[24] == 1",43    "String after the first transformation: \"bcdzz\"",44    "'b' becomes 'c' as nums[1] == 1",45    "'c' becomes 'd' as nums[2] == 1",46    "'d' becomes 'e' as nums[3] == 1",47    "'z' becomes 'ab' as nums[25] == 2",48    "'z' becomes 'ab' as nums[25] == 2",49    "String after the second transformation: \"cdeabab\"",50    "First Transformation (t = 1):\n\n'a' becomes 'bc' as nums[0] == 2\n'z' becomes 'ab' as nums[25] == 2\n'b' becomes 'cd' as nums[1] == 2\n'k' becomes 'lm' as nums[10] == 2\nString after the first transformation: \"bcabcdlm\"",51    "'a' becomes 'bc' as nums[0] == 2",52    "'z' becomes 'ab' as nums[25] == 2",53    "'b' becomes 'cd' as nums[1] == 2",54    "'k' becomes 'lm' as nums[10] == 2",55    "String after the first transformation: \"bcabcdlm\"",56    "Final Length of the string: The string is \"bcabcdlm\", which has 8 characters.",57    "'a' becomes 'bc' as nums[0] == 2",58    "'z' becomes 'ab' as nums[25] == 2",59    "'b' becomes 'cd' as nums[1] == 2",60    "'k' becomes 'lm' as nums[10] == 2",61    "String after the first transformation: \"bcabcdlm\"",62    "1 <= s.length <= 105",63    "s consists only of lowercase English letters.",64    "1 <= t <= 109",65    "nums.length == 26",66    "1 <= nums[i] <= 25"67  ],68  "python_template": "class Solution(object):\n    def lengthAfterTransformations(self, s, t, nums):\n        \"\"\"\n        :type s: str\n        :type t: int\n        :type nums: List[int]\n        :rtype: int\n        \"\"\"\n        ",69  "java_template": "class Solution {\n    public int lengthAfterTransformations(String s, int t, List<Integer> nums) {\n        \n    }\n}",70  "metadata": {71    "func_name": "lengthAfterTransformations"72  }73}