Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes399downloads
shift-distance-between-two-strings.json41 linesDownload Raw Back to root
1{2  "id": 3591,3  "name": "shift-distance-between-two-strings",4  "difficulty": "Medium",5  "link": "https://leetcode.com/problems/shift-distance-between-two-strings/",6  "date": "2024-11-09",7  "task_description": "You are given two strings `s` and `t` of the same length, and two integer arrays `nextCost` and `previousCost`. In one operation, you can pick any index `i` of `s`, and perform **either one** of the following actions: Shift `s[i]` to the next letter in the alphabet. If `s[i] == 'z'`, you should replace it with `'a'`. This operation costs `nextCost[j]` where `j` is the index of `s[i]` in the alphabet. Shift `s[i]` to the previous letter in the alphabet. If `s[i] == 'a'`, you should replace it with `'z'`. This operation costs `previousCost[j]` where `j` is the index of `s[i]` in the alphabet. The **shift distance** is the **minimum** total cost of operations required to transform `s` into `t`. Return the **shift distance** from `s` to `t`. **Example 1:** **Input:** s = \"abab\", t = \"baba\", nextCost = [100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], previousCost = [1,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] **Output:** 2 **Explanation:** We choose index `i = 0` and shift `s[0]` 25 times to the previous character for a total cost of 1. We choose index `i = 1` and shift `s[1]` 25 times to the next character for a total cost of 0. We choose index `i = 2` and shift `s[2]` 25 times to the previous character for a total cost of 1. We choose index `i = 3` and shift `s[3]` 25 times to the next character for a total cost of 0. **Example 2:** **Input:** s = \"leet\", t = \"code\", nextCost = [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,1], previousCost = [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,1] **Output:** 31 **Explanation:** We choose index `i = 0` and shift `s[0]` 9 times to the previous character for a total cost of 9. We choose index `i = 1` and shift `s[1]` 10 times to the next character for a total cost of 10. We choose index `i = 2` and shift `s[2]` 1 time to the previous character for a total cost of 1. We choose index `i = 3` and shift `s[3]` 11 times to the next character for a total cost of 11. **Constraints:** `1 <= s.length == t.length <= 105` `s` and `t` consist only of lowercase English letters. `nextCost.length == previousCost.length == 26` `0 <= nextCost[i], previousCost[i] <= 109`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "s = \"abab\", t = \"baba\", nextCost = [100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], previousCost = [1,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]",12      "output": "2 "13    },14    {15      "label": "Example 2",16      "input": "s = \"leet\", t = \"code\", nextCost = [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,1], previousCost = [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,1]",17      "output": "31 "18    }19  ],20  "constraints": [21    "Shift s[i] to the next letter in the alphabet. If s[i] == 'z', you should replace it with 'a'. This operation costs nextCost[j] where j is the index of s[i] in the alphabet.",22    "Shift s[i] to the previous letter in the alphabet. If s[i] == 'a', you should replace it with 'z'. This operation costs previousCost[j] where j is the index of s[i] in the alphabet.",23    "We choose index i = 0 and shift s[0] 25 times to the previous character for a total cost of 1.",24    "We choose index i = 1 and shift s[1] 25 times to the next character for a total cost of 0.",25    "We choose index i = 2 and shift s[2] 25 times to the previous character for a total cost of 1.",26    "We choose index i = 3 and shift s[3] 25 times to the next character for a total cost of 0.",27    "We choose index i = 0 and shift s[0] 9 times to the previous character for a total cost of 9.",28    "We choose index i = 1 and shift s[1] 10 times to the next character for a total cost of 10.",29    "We choose index i = 2 and shift s[2] 1 time to the previous character for a total cost of 1.",30    "We choose index i = 3 and shift s[3] 11 times to the next character for a total cost of 11.",31    "1 <= s.length == t.length <= 105",32    "s and t consist only of lowercase English letters.",33    "nextCost.length == previousCost.length == 26",34    "0 <= nextCost[i], previousCost[i] <= 109"35  ],36  "python_template": "class Solution(object):\n    def shiftDistance(self, s, t, nextCost, previousCost):\n        \"\"\"\n        :type s: str\n        :type t: str\n        :type nextCost: List[int]\n        :type previousCost: List[int]\n        :rtype: int\n        \"\"\"\n        ",37  "java_template": "class Solution {\n    public long shiftDistance(String s, String t, int[] nextCost, int[] previousCost) {\n        \n    }\n}",38  "metadata": {39    "func_name": "shiftDistance"40  }41}